Previous task
Structure of HTML page6/10
Back to the list of tasks
  1. 1. Where HTML begins
  2. 2. The simplest HTML page
  3. 3. HTML page title
  4. 4. HTML page encoding
  5. 5. Connecting styles
  6. 6. Connecting external styles
  7. 7. The mystery of the CSS editor
  8. 8. Connecting scripts
  9. 9. Connecting external scripts
  10. 10. Connecting external styles and scripts again
Nest task
  • Courses
  • Sign up
  • Log in

Loading...
It will be ready in a few seconds.

  • Theory
  • Theory

Connecting external styles

Most often styles are connected from an external file with the extension .css. For this purpose, the <link> tag is used. For example:

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

The href attribute specifies the file address, and the rel="stylesheet" attribute tells the browser that we're plugging in styles and not something else.

It is better to include styles inside <head>, but it is not necessary. The <link> tag will work elsewhere on the page.

In this assignment, you will plug in an external style file, which is located at external.css(follow the link to open this file in your browser).

  • index.html
HTML
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Connecting external styles</title> <!-- connect external styles here --> </head> <body> <h1>External Styles</h1> <p>External styles are much more convenient than inline styles because you can plug the same style file into many pages.</p> <p>If you need to make changes to a style, you change one file and the changes appear on all pages where it's plugged in.</p> <p>With inline styles, this would be a bit of a hassle.</p> </body> </html>

The code has changed, click "Update" or enable autorun.

You have moved to another page

Click inside the mini-browser to highlight this window.

100%
GoalsCompleted
0

    Connect an external style file to the page. To do this:

    1. Add a <link> tag inside <head>,
    2. give it a rel attribute with the value stylesheet
    3. and a href attribute with the value external.css.

    © 2023-2024, codehero.pro