This declaration is an instruction and must be the first line of an HTML document. It specifies the document type and version of HTML being used. In modern usage, <!DOCTYPE html> indicates HTML5.
<!DOCTYPE html>
<html>
...
</html>
This is a quick reference cheat sheet for understanding and writing JSON format configuration files.
This declaration is an instruction and must be the first line of an HTML document. It specifies the document type and version of HTML being used. In modern usage, <!DOCTYPE html> indicates HTML5.
<!DOCTYPE html>
<html>
...
</html>
Semantic HTML
The <head> element contains metadata and resource links that configure your HTML document. It typically includes information that is not directly displayed on the page but is essential for setting up the page’s environment.
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Page Title</title>
<link rel="stylesheet" href="styles.css">
<link rel="icon" href="favicon.ico" type="image/x-icon">
<script src="script.js"></script>
</head>
The <form> element collects user input and sends it to a server. Its key attributes are defined below:
<form action="/example.html" method="POST">
...
</form>
The <input> element is a self-closing tag used to create interactive controls for forms
<input type="text" name="first-text-field" value="already pre-filled" />
Assign a default value to an input field using the value attribute. This pre-fills the field when the form is first rendered.
<form action="/example.html" method="POST">
<input type="text" name="first-text-field" value="already pre-filled">
</form>
If a user submits the form with a custom string like important details, the following data will be sent:
first-text-field=important details
The value sent is based on the name attribute ("first-text-field") and the user’s input ("important details").
The <label> element defines a caption for an <input> element. To associate a label with an input, the input must have an id and the label’s for attribute must match that id.
<label for="meal">What do you want to eat?</label>
<input type="text" name="food" id="meal" />
The <input type="text"> element creates a single-line text field where users can enter plain text.
<input type="text" name="first-text-field">
<input> type
The <input type="password"> element creates a text field where the input characters are masked (e.g., shown as asterisks * or dots •).
<form>
<label for="user-password">Password: </label>
<input type="password" id="user-password" name="user-password">
</form>
This type is typically used for sensitive information like login passwords.
<input> type
The <input type="number"> element restricts input to numbers (and a few special characters like -
, +
, and .
).
<form>
<label for="years">Years of experience: </label>
<input id="years" name="years" type="number" step="1">
</form>
The step attribute adds arrows to the field that increment or decrement the value by the specified amount.
<input> type
The <input type="range"> element creates a slider control that lets users select a numeric value within a specified range.
<form>
<label for="volume">Volume Control</label>
<input id="volume" name="volume" type="range" min="0" max="100" step="1">
</form>
The min and max attributes define the range of selectable values, while the step attribute controls how much each movement of the slider adjusts the value.
<input> type
The <input type="checkbox"> element allows users to select one or multiple options from a set of choices.
<form>
<p>Choose your pizza toppings:</p>
<label for="cheese">Extra cheese</label>
<input id="cheese" name="topping" type="checkbox" value="cheese">
<br>
<label for="pepperoni">Pepperoni</label>
<input id="pepperoni" name="topping" type="checkbox" value="pepperoni">
</form>
Each checkbox works independently, and multiple boxes can be selected at the same time.
<input> type
The <select> element creates a dropdown list, and is populated with <option> elements. It is used to choose one value among many.
<form>
<label for="lunch">What's for lunch?</label>
<select id="lunch" name="lunch">
<option value="pizza">Pizza</option>
<option value="curry">Curry</option>
<option value="salad">Salad</option>
<option value="ramen">Ramen</option>
<option value="tacos">Tacos</option>
</select>
</form>
If a user selects Pizza, the data sent will be "lunch=pizza."
The <datalist> element provides a list of predefined options to suggest to the user as they input data. It is used with an input element's list attribute.
<form>
<label for="city">Ideal city to visit?</label>
<input type="text" list="cities" id="city" name="city" />
<datalist id="cities">
<option value="New York City"></option>
<option value="Tokyo"></option>
<option value="Barcelona"></option>
<option value="Mexico City"></option>
<option value="Melbourne"></option>
<option value="Other"></option>
</datalist>
</form>
The <textarea> element creates a multi-line text input field. It supports attributes such as rows and cols to define its visible size, and can contain default text.
<form>
<label for="blog">New Blog Post:</label>
<br />
<textarea id="blog" name="blog" rows="5" cols="30">
Default text
</textarea>
</form>
Required, text length restrictions and pattern matching.
<form action="/example.html" method="POST">
<label for="username">Username:</label>
<br>
<input id="username" name="username" type="text" minlength="3" maxlength="15"
pattern="^[A-Za-z0-9_]+$" required>
<br>
<input type="submit" value="Register">
</form>
<input> attributes
Client-side validation is performed directly in the user's browser. It provides instant feedback but cannot be fully trusted because it can be bypassed.
Improve the user experience by catching errors before the form is submitted.
Use vanilla JavaScript, simple libraries like just-validate, or framework-specific libraries like formik for React.
Users can disable JavaScript or manipulate the front-end, so client-side validation alone is not secure.
Server-side validation happens on the server after data is submitted. It is critical for security and database integrity.
Protect the server and database from invalid, malicious, or manipulated input data.
Asynchronous validation: Checks parts of data before submission, offering live feedback (but slower).
Post-submission validation: Validates after form submission and includes sanitization for consistent database entries.
Important: The server-side validation should be implemented even if client-side checks exist.
Font Awesome is a popular icon library used to visually convey actions and information. Icons are implemented as CSS classes, making them easy to style and resize.
The Font Awesome library is linked to an HTML document via the <link> tag
<head>
<!-- CDN Version -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5.15.4/css/fontawesome.min.css">
<!-- Local Version -->
<link rel="stylesheet" href="resources/css/fontawesome.css">
</head>
Font Awesome icons are added using an <i> tag with two required classes: the base fa class and an icon-specific class (e.g. fa-save).
<i class="fa fa-save"></i>
In this example, the fa-save class displays the floppy disk icon commonly associated with saving.
Icon sizes can be adjusted with additional classes:
<i class="fa fa-camera fa-lg"></i>
<i class="fa fa-cab fa-4x"></i>