The stylesheet is used in HTML to describe how a document is presented on screen. With CSS, easily specify a number of style properties for an HTML element. Each property has a name and a value, which is separated by a colon (:).
You can use CSS in three ways in your HTML document −
- External Style Sheet − Define style sheet rules in a separate .css file and then include that file in your HTML document using HTML <link> tag.
- Internal Style Sheet − Define style sheet rules in header section of the HTML document using <style> tag.
- Inline Style Sheet − Define style sheet rules directly along-with the HTML elements using style attribute.
Just keep in mind each property declaration is separated by a semi-colon (;). Use the style attribute to add CSS to the HTML elements and attribute. This is how you can add inline style sheet and set text color −
Example
You can try to run the following code to add a style sheet to an HTML page
<!DOCTYPE html> <html> <head> <title>HTML style sheet</title> </head> <body> <h1 style="color:red"> Heading </h1> <p style="color:blue"> This is demo text </p> </body> </html>