Languages
[Edit]
EN

HTML - add css to html

19 points
Created by:
Palpys
764

In this article, we would like to show how to add styles to HTML code (how to add CSS to HTML).

The most popular approaches are: using link tag, style tag and  style attribute.

Quick solutions:

1. Link to stylesheet file (*.css file):

Hint: put it to <head> element.

2. Embedded styles:

Hint: put it somewhere in the source code.

3. Inline styles:

 

This article is like an overview of different approaches with examples.

Practical examples

Edit

1. Link to stylesheet file example

Edit

index.htm file:

styles.css file:

Result:

Link to stylesheet file example.
Link to stylesheet file example.

2. Embed CSS (style tag) example

Edit

index.htm file:

Result:

Embed CSS (style tag) example.
Embed CSS (style tag) example.

3. Inline styles example

Edit

index.htm file:

Result:

Inline styles example.
Inline styles example.

4. Import of stylesheet file example

Edit

index.htm file:

styles.css file:

Result:

Import of stylesheet file example.
Import of stylesheet file example.

5. JavaScript CSS file injection example

Edit

index.htm file:

styles.css file:

Result:

JavaScript CSS file injection example.
JavaScript CSS file injection example.

6. JavaScript Embed CSS (style tag) injection example

Edit

index.htm file:

Result:

JavaScript style tag injection example.
JavaScript style tag injection example.

7. JavaScript inline styles example

Edit

index.htm file:

Result:

JavaScript inline styles example.
JavaScript inline styles example.

    Alternative titles

    1. HTML - how to attach css to html?
    2. HTML - how to add css file to html?
    3. HTML - how to add style file to html?
    4. HTML - how to attach style file to html?
    5. HTML - different ways how to attach style to html?
    6. HTML - different ways how to add style file to html?
    7. HTML - how to include css to html?
    8. HTML - how to import css to html?
    9. HTML - how to import style to html?
    1
    Donate to Dirask
    Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
    Join to our subscribers to be up to date with content, news and offers.

    HTML

    Native Advertising
    🚀
    Get your tech brand or product in front of software developers.
    For more information Contact us
    Dirask - we help you to
    solve coding problems.
    Ask question.

    ❤️💻 🙂

    Join