How do you add CSS styling in HTML?

There are three ways to include the CSS with HTML:

  • Inline CSS: It is used when less amount of styling is needed or in cases where only a single element has to be styled. To use inline styles add the style attribute in the relevant tag.
  • External Style Sheet: This is used when the style is applied to many elements or HTML pages. Each page must link to the style sheet using the <link> tag:

<head>

  <link rel=”stylesheet” type=”text/css” href=”mystyle.css” />

</head>

  • Internal Style Sheet: It is used when a single HTML document has a unique style and several elements need to be styled to follow the format. Internal styles sheet is added in the head section of an HTML page, by using the <style> tag:

<head>

  <style type=”text/css”>

    hr {

      color: sienna;

    }

    p {

      margin-left: 20px;

    }

    body {

      background-image: url(“images/back40.gif”);

    }

  </style>

</head>


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *