Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.


    Load External CSS with the Link Element

    htmlHTML 5

    The link element is most commonly used to load external stylesheets. This lesson demonstrates the basics of creating a link element and using a link element to load the popular Bootstrap library.



    Become a Member to view code

    You must be a Pro Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson
    orLog In




    Instructor: Create a new file, and I'll call this index.html. Then I can generate the necessary HTML elements using exclamation point, and hitting tab. Then I'll just write hello inside the body, make sure to save this, and we can preview this by dragging it over into our browser address bar. You can see this hello here is reflected in the browser.

    Now, you can create a link tag by typing link, then hitting the tab. You can see the element that this generates has an R-E-L, or relationship, of stylesheet, and a blank href, or hypertext reference. This is, by far, the most common scenario for links, where you want to load in a style sheet, and you'd add the reference where that style sheet is located.

    If you go ahead and google Bootstrap CDN, which is a very famous CSS library, you'll land on bootstrapcdn.com. You can just come here and click on this link, which copies the link to the clipboard. Then click here, and paste it inside the href attribute.

    I'll switch back over to my document, refresh the page, and you can see my hello now has new styles applied. Let's make that bigger by creating a large header, and calling this hello. Then we'll add a button that says click me, and we'll add some CSS classes from Bootstrap, such as button and button-primary.

    We'll save this, hit refresh, and you can see this hello reflected here, and a styled button with the Bootstrap classes right here. If I remove this link -- I'll delete that entire line, hit save, and refresh -- you'll see all the styles disappear, because the style sheet is no longer referenced.

    I'll hit undo, bring it back, and refresh. We now, again, have the styles from our referenced style sheet. Note that with the link element, you look at the end of it. There is no closing tag, like you see with title, header one, or body.

    A link element is an empty element. There will never been content between an opening link tag and a closing link tag. That way, it's more similar to the input element, or an image element, where the content and display of the element is defined within the attributes of the element itself, not the content inside of the element.