How to apply CSS styles?

0136

To apply CSS styles to your HTML documents, you can use one of the following methods:

  1. Inline CSS: Add styles directly to an HTML element using the style attribute.

    <h1 style="color: blue; text-align: center;">Hello World</h1>
    
  2. Internal CSS: Include a <style> tag within the <head> section of your HTML document.

    <head>
        <style>
            body {
                background-color: lightgray;
            }
            h1 {
                color: green;
            }
        </style>
    </head>
    
  3. External CSS: Create a separate CSS file (e.g., style.css) and link it to your HTML document.

    <head>
        <link rel="stylesheet" href="style.css" />
    </head>
    

    In style.css, you can write your CSS rules:

    body {
        background-color: lightgray;
    }
    h1 {
        color: green;
    }
    

Choose the method that best fits your project needs. External CSS is generally preferred for larger projects as it keeps your HTML clean and separates content from presentation.

0 Comments

no data
Be the first to share your comment!