How to use inline CSS (Style Sheet) in HTML?


Cascading Style Sheets is used to format the presentation of a webpage.

CSS is used to style and layout web pages - you can control the presentation of the web page using, to alter the font, color, size, and spacing of your content, split it into multiple columns, or add animations and other decorative features available within the css properties.

  • Inline − Using the style attribute inside HTML elements.

  • Inline CSS − Inline CSS is used to apply a unique style to a single HTML element used within the tag.

Example

Following is the example program, uses inline CSS for styling in HTML.

<!DOCTYPE html> <html> <head> <h1 style="font-family: fantasy">HTML</h1> </head> <body style="background-color: bisque"> <p style="background:yellow" >HTML is used to structure a web page and its content.</p> </body> </html>

Example

Following is the example program, uses inline CSS for styling for <h1> and <h2> elements.

<!DOCTYPE html> <html> <head> <h1 style="font-family: fantasy">HTML</h1> </head> <body style="background-color: seagreen"> <h2 style="background:whitesmoke" >HTML is used to structure a web page and its content.</h2> </body> </html>

Example

Following is the example program, uses inline CSS for styling for <table> element.

<!DOCTYPE html> <html> <head> <title>Inline CSS</title> </head> <body> <table style = "border: 1px solid";> <tr> <th>Firstname</th> <th>Lastname</th> </tr> <tr> <td>Peter</td> <td>Griffin</td> </tr> <tr> <td>Lois</td> <td>Griffin</td> </tr> </table> </body> </html>

Updated on: 11-Nov-2022

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements