Key Concepts

Review core concepts you need to learn to master this subject

HTML Acronym and Markup Languages

The acronym HTML stands for HyperText Markup Language. A markup language is a computer annotation system for defining the structure and presentation of text.

HTML Usage

HTML is used to give content to a web page and instructs web browsers on how to structure that content.

HTML Element

An HTML element is a piece of content in an HTML document and uses the following syntax: opening tag + content + closing tag. In the code provided:

  • <p> is the opening tag.
  • Hello World! is the content.
  • </p> is the closing tag.

HTML Tag

The syntax for a single HTML tag is an opening angle bracket < followed by the element name and a closing angle bracket >. Here is an example of an opening <div> tag.

Element Content

The content of an HTML element is the information between the opening and closing tags of an element. In the example, the element content is “Codecademy is awesome!”.

Closing Tag

An HTML closing tag is used to denote the end of an HTML element. The syntax for a closing tag is a left angle bracket < followed by a forward slash / then the element name and a right angle bracket to close >.

<body> Body Element

The <body> element represents the content of an HTML document. Content inside <body> tags are rendered on the web browsers.

The Body Element Usage (cont.)

The <body> element should contain all content meant to be rendered to a web page. There can be one <body> element per HTML document.

HTML Structure

HTML is organized into a family tree structure. HTML elements can have parents, grandparents, siblings, children, grandchildren, etc.

<h1> <h2> <h3> <h4> <h5> <h6> Headings

HTML can use six different levels of heading elements. The heading elements are ordered from the highest level <h1> to the lowest level <h6>.

<div> Div Element

The <div> element is used as a container that divides an HTML document into sections and is short for “division”. <div> elements can contain flow content such as headings, paragraphs, links, images, etc.

HTML Attributes

HTML attributes are values added to the opening tag of an element to configure the element or change the element’s default behavior. In the provided example, we are giving the <p> (paragraph) element a unique identifier using the id attribute and changing the color of the default text using the style attribute.

Attribute Name and Values

HTML attributes consist of a name and a value using the following syntax: name="value" and can be added to the opening tag of an HTML element to configure or change the behavior of the element.

Unique ID Attributes

In HTML, specific and unique id attributes can be assigned to different elements in order to differentiate between them.

When needed, the id value can be called upon by CSS and JavaScript to manipulate, format, and perform specific instructions on that element and that element only. Valid id attributes should begin with a letter and should only contain letters (a-Z), digits (0-9), hyphens (-), underscores (_), and periods (.).

<p> Paragraph Element

Paragraph elements, <p>, contain and display blocks of text.

<span> Element

The <span> element is an inline container for text and can be used to group text for styling purposes. However, as <span> is a generic container to separate pieces of text from a larger body of text, its use should be avoided if a more semantic element is available.

<em> Emphasis Element

The <em> emphasis element emphasizes text and browsers will usually italicize the emphasized text by default.

<strong> Strong Element

The <strong> element highlights important, serious, or urgent text and browsers will normally render this highlighted text in bold by default.

<br> Line Break Element

The <br> line break element will create a line break in text and is especially useful where a division of text is required, like in a postal address. The line break element requires only an opening tag and must not have a closing tag.

<ul> Unordered List Element

The <ul> unordered list element is used to create a list of items in no particular order. Each individual list item will have a bullet point by default. For example:

  • Oculus Quest
  • Fender Telecaster
  • Record Player

<li> List Item Element

The <li> list item element create list items inside:

  • Ordered lists <ol>
  • Unordered lists <ul>

<ol> Ordered List Elements

HTML ordered list, <ol>, elements are used to create lists of items with a sequential order. Each list item in an ordered list appears numbered by default. For example:

  1. Code every day.
  2. Build a portfolio.
  3. Never give up.

<img> Image Element

HTML image <img> elements embed images in documents. The src attribute contains the image URL and is mandatory. <img> is an empty element meaning it should not have a closing tag.

alt Attribute

An <img> element can have alternative text via the alt attribute. The alternative text will be displayed if an image fails to render due to an incorrect URL, if the image format is not supported by the browser, if the image is blocked from being displayed, or if the image has not been received from the URL.

HTML alt attribute for screen-reading

The alternative text on an image element, the alt attribute value, will be read aloud if screen reading software is used and helps support visually impaired users by providing a text descriptor for the image content on a webpage.

<video> Video Element

The <video> element embeds a media player into an HTML document for video playback. The src attribute will contain the URL to the video. Adding the controls attribute will display video controls in the media player.

The <video> element can contain text content between its opening and closing tags which will be displayed if the browser does not support the video format or if the video fails to load.

Document Type Declaration

The document type declaration <!DOCTYPE html> is required as the first line of an HTML document. The doctype declaration is an instruction to the browser about what type of document to expect and which version of HTML is being used, in this case it’s HTML5.

<html> Element

The <html> element, the root of an HTML document, should be added after the !DOCTYPE declaration. All content/structure for an HTML document should be contained between the opening and closing <html> tags.

<head> Element

The <head> element contains general information about an HTML page that isn’t displayed on the page itself. This information is called metadata and includes things like the title of the HTML document and links to stylesheets.

<title> Title Element

The <title> element contains a text that defines the title of an HTML document. The title is displayed in the browser’s title bar or tab in which the HTML page is displayed. The <title> element can only be contained inside a document’s <head> element.

<a> Anchor Element

The <a> anchor element is used to create hyperlinks in an HTML document. The hyperlinks can point to other webpages, files on the same server, a location on the same page, or any other URL via the hyperlink reference attribute, href. The href determines the location the anchor element points to.

<target> Attribute

The target attribute on an anchor (<a>) element specifies where a hyperlink should be opened. For example, a target value of "_blank" will tell the browser to open the hyperlink in a new tab in modern browsers, or in a new window in older browsers or if the browser has had settings changed to open hyperlinks in a new window.

File Path

URL paths in HTML can be absolute paths, like a full URL, for example: https://developer.mozilla.org/en-US/docs/Learn or a relative file path that links to a local file in the same folder or on the same server, for example: ./style.css. Relative file paths begin with ./ followed by a path to the local file. ./ tells the browser to look for the file path from the current folder.

# Linking to Spot on the Same Page

The HTML anchor element, <a> can create hyperlinks to different parts of the same HTML document using the href attribute to point to the desired location with # followed by the id of the element to link to.

Whitespace

Whitespace, such as line breaks, added to an HTML document between block-level elements will generally be ignored by the browser and are not added to increase spacing on the rendered HTML page. Rather, whitespace is added for organization and easier reading of the HTML document itself.

Indenting Nested in HTML

HTML code should be formatted such that the indentation level of text increases once for each level of nesting. The W3C standards recommend two spaces of indentation per level of nesting.

Comments

In HTML, comments can be added between an opening <!-- and closing -->. Content inside of comments will not be rendered by browsers, and are usually used to describe a part of code or provide other details.

Comments can span single or multiple lines.

Chevron Left Icon
Introduction to HTML
Lesson 1 of 2
Chevron Right Icon
  1. 1
    Welcome to the world of code! Last year, millions of learners from our community started with HTML. Why? HTML is the skeleton of all web pages. It’s often the first language learned by marketers an…
  2. 2
    HTML is composed of elements. These elements structure the webpage and define its content. Let’s take a look at how they’re written. The diagram to the right displays an HTML paragraph element. …
  3. 3
    One of the key HTML elements we use to build a webpage is the body element. Only content inside the opening and closing body tags can be displayed to the screen. Here’s what opening and closing b…
  4. 4
    HTML is organized as a collection of family tree relationships. As you saw in the last exercise, we placed tags within tags. When an element is contained inside another element, it is consider…
  5. 5
    Headings in HTML are similar to headings in other types of media. For example, in newspapers, large headings are typically used to capture a reader’s attention. Other times, headings are used to de…
  6. 6
    One of the most popular elements in HTML is the element. is short for “division” or a container that divides the page into sections. These sections are very useful for grouping elements in your…
  7. 7
    If we want to expand an element’s tag, we can do so using an attribute. Attributes are content added to the opening tag of an element and can be used in several different ways, from providing inf…
  8. 8
    If you want to display text in HTML, you can use a paragraph or span: - Paragraphs ( ) contain a block of plain text. - contains short pieces of text or other HTML. They are used to separat…
  9. 9
    You can also style text using HTML tags. The tag emphasizes text, while the tag highlights important text. Later, when you begin to style websites, you will decide how you want browsers to di…
  10. 10
    The spacing between code in an HTML file doesn’t affect the positioning of elements in the browser. If you are interested in modifying the spacing in the browser, you can use HTML’s line break el…
  11. 11
    In addition to organizing text in paragraph form, you can also display content in an easy-to-read list. In HTML, you can use an unordered list tag ( ) to create a list of items in no particular …
  12. 12
    Ordered lists ( ) are like unordered lists, except that each list item is numbered. They are useful when you need to list different steps in a process or rank items for first to last. You can …
  13. 13
    All of the elements you’ve learned about so far (headings, paragraphs, lists, and spans) share one thing in common: they’re composed entirely of text! What if you want to add content to your web pa…
  14. 14
    Part of being an exceptional web developer is making your site accessible to users of all backgrounds. In order to make the Web more inclusive, we need to consider what happens when assistive techn…
  15. 15
    In addition to images, HTML also supports displaying videos. Like the tag, the tag requires a src attribute with a link to the video source. Unlike the tag however, the element requires an …
  16. 16
    Congratulations on completing the first lesson of HTML! You are well on your way to becoming a skilled web developer. Let’s review what you’ve learned so far: 1. HTML stands for Hyper*T
  1. 1
    Now that you’ve learned about some of the most common HTML elements, it’s time to learn how to set up an HTML file. HTML files require certain elements to set up the document properly. You can le…
  2. 2
    The declaration provides the browser with two pieces of information (the type of document and the HTML version to expect), but it doesn’t actually add any HTML structure or content. To create …
  3. 3
    So far you’ve done two things to set up the file properly: Declared to the browser that your code is HTML with Added the HTML element ( ) that will contain the rest of your code. We have add…
  4. 4
    What kind of metadata about the web page can the element contain? If you navigate to the Codecademy catalog and look at the top of your browser, you’ll notice the words Catalog | Codecademy,…
  5. 5
    Good work! Unfortunately, the browser panel used by the Codecademy environment does not have a title bar, so the “Brown Bear” title you wrote in the previous exercise will not be displayed. Outside…
  6. 6
    One of the powerful aspects of HTML (and the Internet), is the ability to link to other web pages. You can add links to a web page by adding an anchor element and including the text of the …
  7. 7
    Have you ever clicked on a link and observed the resulting web page open in a new browser window? If so, you can thank the element’s target attribute. The target attribute specifies how a link s…
  8. 8
    Thus far you have learned how to link to external web pages. Many sites also link to internal web pages like Home, About, and Contact. Before we learn how to link between internal pages, let’s est…
  9. 9
    You’ve probably visited websites where not all links were made up of text. Maybe the links you clicked on were images or some other form of content. So far, we’ve added links that were made up of …
  10. 10
    At this point, we have all the content we want on our page. Since we have so much content, it doesn’t all fit on the screen. How do we make it easier for a user to jump to different portions of our…
  11. 11
    The rest of this lesson will focus on some tools developers use to make code easier to interpret. As the code in an HTML file grows, it becomes increasingly difficult to keep track of how elements…
  12. 12
    The second tool web developers use to make the structure of code easier to read is indentation. The spaces are inserted using the space and tab bars on your keyboard. The World Wide Web C…
  13. 13
    HTML files also allow you to add comments to your code. Comments begin with . Any characters in between will be ignored by your browser. Including comments in your code is helpful for many r…
  14. 14
    You now know all of the basic elements and set-up you need to structure an HTML page and add different types of content. With the help of CSS, very soon you’ll be creating beautiful websites! Whil…

What you'll create

Portfolio projects that showcase your new skills

Pro Logo

How you'll master it

Stress-test your knowledge with quizzes that help commit syntax to memory

Pro Logo