Structure and Design your website: Html & Css for Beginners
HTML Elements & Tags
Header
<header>
: Defines a header for a document or section.<h1>
to<h6>
: Heading elements<nav>
: Navigation links.<logo>
: Typically an image or icon representing the site's brand (not an actual HTML tag, usually an<img>
inside a<a>
).
Navigation
<nav>
: Navigation links.<a>
: Hyperlinks to other pages or content.<ul>
,<ol>
,<li>
: Lists of items, often used for navigation menus.
Main Content
<main>
: The main content of the document.<section>
: Sections of content within<main>
.<article>
: A self-contained composition in a document that is independently distributable or reusable.<p>
: Paragraphs.pre
: Preformatted text.<img>
: Images.<video>
: Video files.<audio>
: Audio files.<canvas>
: Used for drawing graphics via scripting.
Article
<article>
: A self-contained composition.<h1>
,<h2>
, ...<h6>
: Headings within the article.<p>
: Paragraphs.<figure>
: Images, diagrams, photos, code listings, etc., that are referenced in the main flow of an article.<figcaption>
: A caption or legend describing the figure.
Aside
<aside>
: Content tangentially related to the content around the aside element.<ul>
,<ol>
: Lists that might summarize other content or link to related content.
Figure
<figure>
: Self-contained content, frequently referenced as a single unit from the main content.<figcaption>
: Caption that provides a description of the figure.
Form
<form>
: Interactive controls for submitting information.<input>
: Input fields.<label>
: Labels for<input>
elements.<button>
: Buttons.<select>
,<option>
: Dropdown lists.<textarea>
: Multi-line text input.<fieldset>
: Groups related elements within a form.<legend>
: Caption for the content of its<fieldset>
.<datalist>
: Specifies a list of pre-defined options for input controls.<output>
: Defines the result of a calculation.
Table
<table>
: Table element.<thead>
: The header content of the table.<tbody>
: The body content of the table.<tfoot>
: The footer content of the table, often used for summarizing the data.<tr>
: Table row.<th>
: Table header cell.<td>
: Table data cell.<caption>
: Title or explanation for the table.
Footers
<footer>
: Defines a footer for a document or section.
HTML Attributes
accept:
- Used with
<input type="file">
to specify the types of files that the server accepts, which helps the user by limiting the file selection to those types only.
- Used with
<input type="file" accept=".jpg, .jpeg, .png">
autocomplete:
- This attribute specifies whether a form or an input field should have autocomplete enabled. Autocomplete allows the browser to predict the value based on user inputs in similar fields.
<input type="text" name="email" autocomplete="email">
capture:
- Used with
<input type="file">
to specify that the media input should be captured directly from the device's camera or microphone, bypassing the selection of existing files.
- Used with
<input type="file" capture="user">
crossorigin:
- This attribute is used on HTML
<img>
,<script>
,<link>
, and<video>
elements to configure CORS (Cross-Origin Resource Sharing) requests for the element.
- This attribute is used on HTML
<img src="https://example.com/image.jpg" crossorigin="anonymous">
dirname:
- When used with
<input>
or<textarea>
, this attribute enables the submission of the directionality of the element, allowing the server to be aware of the text direction.
- When used with
<input type="text" name="text" dirname="text.dir">
disabled:
- Specifies that an input, select, button, or other form element is not interactive and should not be submitted with the form.
<input type="text" disabled>
elementtiming:
- This attribute is used to include the element in the performance timeline API for more detailed monitoring of how elements are rendered on the page.
<img src="logo.png" elementtiming="header-logo">
for:
- Used with
<label>
to specify which form element a label is bound to.
- Used with
<label for="username">Username:</label>
<input type="text" id="username">
max:
- Specifies the maximum value for
<input>
elements of typenumber
,range
,date
, etc.
- Specifies the maximum value for
<input type="number" max="100">
maxlength:
- Defines the maximum number of characters that the user can enter into
<input>
or<textarea>
.
- Defines the maximum number of characters that the user can enter into
<input type="text" maxlength="10">
min:
- Specifies the minimum value for
<input>
elements of typenumber
,range
,date
, etc.
- Specifies the minimum value for
<input type="number" min="1">
minlength:
- Defines the minimum number of characters required in
<input>
or<textarea>
.
- Defines the minimum number of characters required in
<input type="text" minlength="5">
multiple:
- Indicates whether multiple values can be entered in an
<input type="email">
or<input type="file">
.
- Indicates whether multiple values can be entered in an
<input type="file" multiple>
pattern:
- Defines a regular expression against which the
<input>
value is checked.
- Defines a regular expression against which the
<input type="text" pattern="[A-Za-z]{3}">
placeholder:
- Provides a hint to the user about what kind of information is expected in the input field.
<input type="text" placeholder="Enter your name">
readonly:
- Indicates that the input field is not editable, but unlike
disabled
, it will still be submitted with the form.
- Indicates that the input field is not editable, but unlike
<input type="text" readonly value="Read-only text">
rel:
- Specifies the relationship between the current document and the linked document/resource. Commonly used with
<a>
and<link>
elements.
- Specifies the relationship between the current document and the linked document/resource. Commonly used with
<a href="https://example.com" rel="noopener noreferrer">Link</a>
required:
- Indicates that the input field must be filled out before submitting the form.
<input type="text" required>
size:
- Specifies the visible width, in characters, of an
<input>
element.
- Specifies the visible width, in characters, of an
<input type="text" size="10">
step:
- Defines the legal number intervals for an
<input>
element of typenumber
orrange
.
- Defines the legal number intervals for an
<input type="number" step="5">
Global Attributes
accesskey:
- Provides a hint for generating a keyboard shortcut for the current element. The browser typically uses this attribute to enable keyboard navigation.
<button accesskey="h">Help</button>
anchorExperimentalNon-standard:
- This is not a standard attribute and may refer to experimental or proprietary features specific to certain browsers or environments.
autocapitalize:
- Controls whether and how text input is automatically capitalized as it is entered/edited by the user.
<input type="text" autocapitalize="words">
autofocus:
- This Boolean attribute lets you specify that an element should automatically get focus when the page loads.
<input type="text" autofocus>
class:
- Used to specify one or more classnames for an element, which can be used by CSS and JavaScript to perform various tasks.
<div class="container"></div>
contenteditable:
- Indicates whether the content of the element can be edited directly by the user.
<div contenteditable="true">Edit me!</div>
data-*:
- Allows us to store custom data private to the page or application, on any HTML element.
<div data-user="12345" data-status="active"></div>
dir:
- Specifies the text directionality of the element's content.
<p dir="rtl">This is a paragraph in a right-to-left language.</p>
draggable:
- Defines whether the element can be dragged.
<img src="logo.png" draggable="true">
enterkeyhint:
- Provides a hint to the browser on what the enter key could do. It helps in optimizing the keyboard interface.
<input enterkeyhint="send">
exportparts:
- This attribute allows a custom element to expose CSS Shadow Parts in a way that they can be styled directly with stylesheets.
<my-element exportparts="partname"></my-element>
hidden:
- Indicates that the element is not yet, or is no longer, relevant.
<div hidden>This content is hidden.</div>
id:
- Defines a unique identifier for the element.
<div id="header"></div>
inert:
- Indicates that the element and all of its focusable descendants are not focusable.
<div inert>Content not interactive.</div>
inputmode:
- Provides a hint to browsers for devices with on-screen keyboards to help them decide which keyboard to display.
<input inputmode="numeric">
is:
- Used for attaching custom behavior to an element.
<button is="custom-button"></button>
itemid, itemprop, itemref, itemscope, itemtype:
- These attributes are part of the Microdata specification which allows you to nest metadata within existing content on web pages.
<div itemscope itemtype="http://schema.org/Person">
<span itemprop="name">Jane Doe</span>
</div>
lang:
- Specifies the language of the element’s content.
<p lang="en">Hello, world!</p>
nonce:
- A security feature in browsers that ensures that scripts are allowed to execute.
<script nonce="2726c7f26c">
part:
- Allows for style encapsulation by letting an element expose one or more parts for styling purposes.
<my-widget part="header"></my-widget>
popover:
- Not a standard attribute, possibly used in frameworks or libraries for UI enhancements.
slot:
- Used in Web Components, it assigns a slot in a shadow DOM.
<span slot="header">This is a header.</span>
spellcheck:
- Specifies whether the element is to have its spelling and grammar checked or not.
<textarea spellcheck="true"></textarea>
style:
- Contains CSS styling declarations to be applied to the element.
<div style="color: blue;">This text is blue.</div>
tabindex:
- Indicates if its element can be focused, and if/where it participates in sequential keyboard navigation.
<div tabindex="0">Focusable Div</div>
title:
- Contains a text representing advisory information related to the element it belongs to.
<abbr title="Hypertext Markup Language">HTML</abbr>
translate:
- Specifies whether the content of an element should be translated or not.
<p translate="no">Bonjour</p>
Input Types
button:
- A clickable button.
<input type="button" value="Click me">
checkbox:
- A checkbox allowing single or multiple selections.
<input type="checkbox" name="vehicle" value="Bike"> I have a bike
color:
- A control for specifying a color.
<input type="color">
date:
- A control for entering a date.
<input type="date">
datetime-local:
- A control for entering a date and time.
<input type="datetime-local">
email:
- A control for entering an email address.
<input type="email">
file:
- A control that lets the user select a file.
<input type="file">
hidden:
- A control that is not displayed but whose value is submitted to the server.
<input type="hidden">
image:
- A graphical submit button.
<input type="image" src="submit.png">
month:
- A control for entering a month and year.
<input type="month">
number:
- A control for entering a number.
<input type="number">
password:
- A single-line text field whose value is obscured.
<input type="password">
radio:
- A radio button allowing single selection.
<input type="radio
range:
- A control for entering a number whose exact value is not important.
<input type="range">
reset:
- A button that resets the form to its default state.
<input type="reset">
search:
- A single-line text field for entering search strings.
<input type="search">
submit:
- A button that submits the form.
<input type="submit">
tel:
- A control for entering a telephone number.
<input type="tel">
text:
- A single-line text field.
<input type="text">
time:
- A control for entering a time value.
<input type="time">
url:
- A control for entering a URL.
<input type="url">
week:
- A control for entering a week and year.
<input type="week">