#HTML #freecodecamp
It stands for Hypertext Markup Language. HTML consists of tags and attributes. HTML tags give a webpage its structure. You can use HTML tags to add photos, buttons, and other elements to your webpage. HTML elements have an opening and closing tag with content in between. An element without a closing tag is known as a void element.
<openingTag>content</closingTag>
HTML attributes are special words used inside the opening tag of an element to control the element's behaviour.
- All pages should begin with
<!DOCTYPE html>
. This special string is known as a declaration and ensures the browser tries to meet industry-wide specifications. <!DOCTYPE html>
tells browsers that the document is an HTML5 document which is the latest version of HTML.- The
html
element is the root element of an HTML page and wraps all content on the page. You can also specify the language of your page by adding thelang
attribute to thehtml
element. - All page content elements that should be rendered to the page go inside the
body
element. However, other important information goes inside thehead
element. - The
head
element is used to contain metadata about the document, such as its title, links to stylesheets, and scripts. Metadata is information about the page that isn't displayed directly on the page. - You can set browser behaviour by adding
meta
elements in thehead
. Inside thehead
element, nest ameta
element with an attribute namedcharset
. Set to the value toutf-8
which tells the browser how to encode characters for the page. Note that themeta
element is a void element. - The
title
element determines what browsers show in the title bar or tab for the page.
- The
h1
throughh6
heading elements are used to signify the importance of content below them. The lower the number, the higher the importance. - The
p
element is used to create a paragraph of text on websites.- To place emphasis on a specific word or phrase, you can use the
em
element. - The
strong
element is used to indicate that some text is of strong importance or urgent.
- To place emphasis on a specific word or phrase, you can use the
- Commenting allows you to leave messages without affecting the browser display.
- Add images to your website by using the
img
element.img
elements have an opening tag without a closing tag. - A figure caption (
figcaption
) element is used to add a caption to describe the image contained within thefigure
element. - Anchor
a
tags links other pages. A link's text must be placed between the opening and closing tags of an anchora
element. - To create an unordered list of items, you can use the
ul
element. - The code for an ordered list (
ol
) is similar to an unordered list, but list items in an ordered list are numbered when displayed. - The
li
element is used to create a list item in an ordered or unordered list. - The
form
element is used to get information from a user like their name, email, and other details.- The
input
element allows you several ways to collect data from a web form. Likeimg
elements,input
elements are a void element and do not need closing tags. - The
button
element is used to create a clickable button. - You can use radio buttons for questions where you want only one answer out of multiple options.
- The
input
element with atype
attribute set tocheckbox
creates a checkbox. label
elements are used to help associate the text for aninput
element with theinput
element itself.- The
legend
element acts as a caption for the content in thefieldset
element. It gives users context about what they should enter into that part of the form.
- The
- The
footer
element is used to define a footer for a document or section. A footer typically contains information about the author of the document, copyright data, links to terms of use, contact information, and more.
<main>
<section>
<h1>Learn HTML</h1>
<p>This is a paragraph.</p>
<!-- This is a comment -->
<figure>
<img src="https://en.wikipedia.org/wiki/File:HTML5_logo_and_wordmark.svg" alt="HTML">
<figcaption>HTML Logo</figcaption>
</figure>
</section>
<section>
<a href="https://www.freecodecamp.org/learn/2022/responsive-web-design">freecodecamp</a>
<ul>
<li>one</li>
<li>two</li>
</ul>
</section>
</main>
- The
main
element is used to represent the main content of the body of an HTML document. Content inside themain
element should be unique to the document and should not be repeated in other parts of the document. - The
section
element is used to define sections in a document, such as chapters, headers, footers, or any other sections of the document. It is a semantic element that helps with SEO and accessibility. - The
figure
element represents self-contained content and will allow you to associate an image with a caption. - The
fieldset
element is used to group related inputs and labels together in a web form.fieldset
elements are block-level elements, meaning that they appear on a new line.
- All
img
elements should have analt
attribute. Thealt
attribute's text is used for screen readers to improve accessibility and is displayed if the image fails to load. - The
target
attribute ona
element specifies where to open the linked document.target="_blank"
opens the linked document in a new tab or window. - The
action
attribute onform
element indicates where form data should be sent. - Add the
type
attribute with the valuesubmit
to thebutton
to make it clear that it is a submit button.
- There are many kinds of inputs you can create using the
type
attribute. You can easily create a password field, reset button, or a control to let users select a file from their computer. - In order for a form's data to be accessed by the location specified in the
action
attribute, you must give the text field aname
attribute and assign it a value to represent the data being submitted. - Placeholder text
placeholder
is used to give people a hint about what kind of information to enter into an input. - To prevent a user from submitting your form when required information is missing, you need to add the
required
attribute to aninput
element. There's no need to set a value to therequired
attribute. - In order to make a checkbox checked or radio button selected by default, you need to add the
checked
attribute to it. - The
id
attribute is used to identify specific HTML elements. Eachid
attribute's value must be unique from all otherid
values for the entire page.