BM Balmiki Mandal 24 May 2023 10 views 0 comments Html

3 Best Ways to Add CSS to HTML

Mastering Style: 3 Best Ways to Add CSS to Your HTML Documents

There are several ways to add CSS (Cascading Style Sheets) to HTML documents.

Here are three commonly used methods:

  1. Inline CSS:

    • Inline CSS is applied directly within the HTML tags using the style attribute.

    • Example:

      html
      <p style="color: blue; font-size: 16px;">This is a paragraph with inline CSS.</p>
    • While this method is quick and easy, it's generally not recommended for large-scale styling due to maintenance issues.

  2. Internal (or Embedded) CSS:

    • Internal CSS is placed within the <style> element in the head section of the HTML document.

    • Example:

      html
      <!DOCTYPE html>
      <html>
      <head>
        <style>
          p {
            color: green;
            font-size: 18px;
          }
        </style>
      </head>
      <body>
        <p>This is a paragraph with internal CSS.</p>
      </body>
      </html>
    • Internal CSS allows you to define styles for multiple elements in one place, improving maintainability.

  3. External CSS:

    • External CSS involves creating a separate CSS file and linking it to the HTML document using the <link> element.

    • Example:

      styles.css:

      css
      /* styles.css */
      p {
        color: red;
        font-size: 20px;
      }

      index.html:

      html
      <!DOCTYPE html>
      <html>
      <head>
        <link rel="stylesheet" type="text/css" href="styles.css">
      </head>
      <body>
        <p>This is a paragraph with external CSS.</p>
      </body>
      </html>
    • External CSS promotes a clean separation of HTML structure and CSS styles, making it easier to maintain and update styles across multiple pages.

0 Comments

No comments yet, Be the first to comment.

Post a Comment

Please sign in to post a comment.

Related Posts

Create Flip Card Memory Game Using HTML, CSS and JavaScript

Create Flip Card Memory Game in JavaScript Create Flip Card Memory Game in JavaScript is a fun and educationa...

BM Balmiki Mandal 27 May 2023
Conquer the Course with Hurdles – An Exciting HTML5 Sport Game

Experience the Excitement of the Hurdles – HTML5 Sport Game! Are you looking for an exciting and intense spor...

BM Balmiki Mandal 27 May 2023
Sort Eggs - A Fun HTML5 Puzzle Game with Construct3

How to Sort Eggs with HTML5 (Construct3) If you're a farmer or poultry producer looking for an efficient way...

BM Balmiki Mandal 27 May 2023