How to use Style Sheet in HTML?

HTMLWeb DevelopmentFront End Technology

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 −


You can try to run the following code to add a style sheet to an HTML page

<!DOCTYPE html>
      <title>HTML style sheet</title>
      <h1 style="color:red">
      <p style="color:blue">
         This is demo text


Published on 18-Jan-2018 10:14:19