Vs Codeis a Source Code Editor (4)
Vs Codeis a Source Code Editor (4)
The process of communication between the client, browser, and server is as follows:
The text editor has the HTML code of a website. This website can now be
viewed in a beautifully rendered format using a computer program known
as a web browser.
The rendered page is the output screen of our HTML Document which is
the page displayed on the browser.
The Frontend
File Organization
1. Linking a CSS file to HTML: In the <head> section of your HTML file:
2. Linking a JavaScript file to HTML: In the <body> section of your HTML file:
<script src="script.js"></script>
HTML : Hyper Text Mark Up language : 'Hypertext' refers to the linking of text with
other documents, while 'markup language' denotes a language that
utilizes a specific set of tags.
Nested HTML Element = One HTML Element Inside Another HTML Element
In this example, the <b> element (child) is nested inside the <h1> element
(parent).
HTML Attributes
They are placed within the element's opening tag and consist of two
parts: the name and the value.
• Name: Specifies the property for that element.
• Value: Sets the value of that property for the element.
HTML offers multiple ways to select and style elements. Two of the most
commonly used selectors are IDs and Classes. This blog explores what
they are, how to use them, and their differences.
ID Attribute :
Class Attribute :
The class attribute lets you give the same name to multiple HTML
elements. That way, you can easily change their look or behavior all at
once. Classes are not unique and can be assigned to multiple elements.
The style tag in HTML is used to include embedded CSS (Cascading Style
Sheets) within an HTML document. It is commonly placed within the
<head> section of the HTML file, although it can technically be used in the
<body> as well. The style tag allows you to define the look and feel of
various HTML elements on the page, including their colors, sizes, margins,
and other visual styles.
In CSS, elements with IDs are selected using a hash (#) symbol before
the ID, and elements with classes are selected using a dot (.) before the
class name
Title Attribute :
The title attribute shows a small text when you move the mouse over an element.
Style Attribute :
The style attribute applies CSS directly to an element for quick styling.
HTML Comments :
Comments in HTML are like little notes you leave in your code for yourself or
other people.
These notes help make the code easier to understand but don't show up
on the actual website. The web browser just skips over them!
Single-line Comments
Single-line comments are contained within one line. They are useful for
short annotations.
<!-- This is a single-line comment -->
Multi-line Comments
Multi-line comments span across multiple lines, making them ideal for
detailed explanations or temporarily disabling blocks of code.
<!--
This is a multi-line comment.
It spans multiple lines.
-->
Skeletal Tags
<html>
<!-- Content -->
</html>
The <html> tag is the root element that wraps all the content on the page. It
generally contains two main sections: the header (<head>...</head>) and
the body (<body>...</body>).
<head>
<!-- Header Content -->
</head>
The <head> tag contains meta information and the title of the document.
While the title appears in the browser tab, meta information is often used
for SEO purposes.
<title>
// Title Name
</title>
The <title> tag defines the title of the document, which is displayed in the
browser's title tab.
<body>
// Body Content
</body>
The <body> tag encloses the main content of the page, and everything
within this tag is displayed in the browser.
The image below shows the skeletal tags and essential tags needed to
define the layout of a webpage
Heading Tags
In HTML, heading tags ranging from <h1> to <h6> are used to define the
structure and layout of text on a web page. These tags help create a
hierarchical organization of content, making it easier for both users and
search engines to understand the page's content.
Paragraph Tag
The <p> tag is used to format text into distinct paragraphs. Each
paragraph element is separated by automatic empty line spaces above
and below the content, providing a clear visual separation. The tag must
be closed with its corresponding </p> tag.
<p>
<!-- Paragraph content -->
</p>
While the <p> tag is straightforward, you can enhance its functionality
using various attributes like class or id for CSS styling. You can also
include inline styles using the style attribute.
<p class="example" style="color: blue;">
This is a styled paragraph.
</p>
To add a horizontal line in your HTML document, the <hr> tag comes in
handy.
<br>
Anchor Tag
Links are fundamental to navigating the web. In HTML, links are created
using the <a> tag, also known as the Anchor tag.
The "src" and "alt" attributes are essential for the proper functioning of the
<img> tag.
• src attribute: Specifies the path to the image file.
• alt attribute: Provides a text description for the image.
<img src="images/profile_picture.jpg" alt="Profile Picture"/>
Note: To find the image's location, right-click on the image, go to
properties, and check the location field.
Setting Image Dimensions
Although dimensions can be set using the "width" and "height" attributes
in the <img> tag, modern best practices recommend using CSS for this
purpose.
<img src="image.png" alt="Description" width="300"
height="100" />
Note: Styling dimensions and other properties are now more
commonly managed through CSS for better flexibility and
maintainability.
Pre Tag
The <pre> tag serves as an indispensable tool in HTML for displaying
preformatted text, such as code snippets in various programming
languages.
<pre>
<!-- code snippet in any programming language -->
</pre>
The <pre> tag is most effective when you want the text to display on your
HTML page exactly as it was typed, without any formatting changes. It is
especially useful for displaying code snippets or preformatted text from
data files.
HTML Inline Elements
Inline Elements don't start on a new line. It only takes the width required
to cover the content.
HTML elements are generally divided into two categories: Block-level
and Inline elements.
Inline elements do not start on a new line and only take up as much
width as necessary. They are part of the flow within other elements.
Inline elements can contain other inline elements, but they generally
should not contain block-level elements. For example, you could nest a
<strong> (strong emphasis) element within a <span> (a generic inline
container) element, like so:
You can use CSS to style inline elements. However, some properties like
width and height may not apply.
Here is an exhaustive list of the most used Inline Elements:
• <a>
• <abbr>
• <acronym>
• <button>
• <br>
• <big>
• <bdo>
• <b>
• <cite>
• <code>
• <dfn>
• <i>
• <em>
• <img>
• <input>
• <kbd>
• <label>
• <map>
• <object>
• <output>
• <tt>
• <time>
• <samp>
• <script>
• <select>
• <small>
• <span>
• <strong>
• <sub>
• <sup>
• <textarea>
HTML Block Elements
You already know about HTML inline elements. All HTML tags have specific
display behavior: they are either block-level elements or inline elements.
Block-level elements are those that start on a new line and take up the
entire width of their container by default. They essentially claim all the
horizontal space for themselves, pushing any content that comes after
them to a new line.
• <h1>,<h2>,<h3>,<h4>,<h5>,<h6> - Headings
• <p> - Paragraphs
• <hr> - Horizontal rule
• <address> - Address information
• <article> - Article content
• <aside> - Sidebar content
• <blockquote> - Block quotations
• <canvas> - Drawing area
• <dd> - Description in a description list
• <div> - Generic container
• <dl> - Description list
• <dt> - Term in a description list
• <fieldset> - Group of related form elements
• <figcaption> - Caption for a figure
• <figure> - Image or media with a caption
• <footer> - Footer of a section or page
• <form> - HTML form
• <header> - Header of a section or page
• <li> - List item
• <main> - Main content of a document
• <nav> - Navigation links
• <noscript> - Alternate content when JavaScript is not enabled
• <ol> - Ordered list
• <ul> - Unordered list
• <pre> - Preformatted text
• <section> - Standalone section in a document
• <table> - Table
• <video> - Video content
List Tags
You can specify the style of bullet points using the type attribute. It
supports three values:
• disc - default bullet style
• square
• circle
The type attribute specifies the style of numbering. You have several
options:
1. Uppercase Roman Numerals: Use type="I"
2. Lowercase Roman Numerals: Use type="i"
3. Arabic Numerals: Use type="1" (This is the default if the type attribute
is not specified)
4. Lowercase Alphabetical Letters: Use type="a"
5. Uppercase Alphabetical Letters: Use type="A"
The start attribute specifies the starting number for the list.
<ol type="A" start="3">
<li>Pen</li>
<li>Pencil</li>
</ol>
3. Definition list:
<dl>
<dt>Coffee</dt>
<dd>Black hot drink</dd>
<dt>Milk</dt>
<dd>White cold drink</dd>
</dl>
In this example:
• <dl> is the container for the list.
• <dt> defines the terms that you want to explain.
• <dd> contains the definitions or explanations for the terms.
HTML Tables
HTML tables allow you to arrange data like text, images, and links in rows and
columns. You use the <table> tag to start and end a table.
<table>
// table content
</table>
<table>
<tr>
<th>Name</th>
<th>Age</th>
</tr>
<tr>
<td>Harry</td>
<td>100</td>
</tr>
</table>
Adding a Caption
To add a title to your table, you can use the <caption> element. This
element helps both in terms of SEO and accessibility.
Besides <th> for individual header cells, HTML tables allow you to group
header or footer content using <thead> and <tfoot>.
<table>
<thead>
<!-- header content -->
</thead>
<tfoot>
<!-- footer content -->
</tfoot>
<tbody>
<!-- body content -->
</tbody>
</table>
Column Groups
You can use the <colgroup> and <col> elements to apply styles to an
entire column in an HTML table.
<table>
<colgroup>
<col style="background-color:yellow">
</colgroup>
<!-- rest of the table -->
</table>
Accessibility in Tables
To make your tables more accessible, you can use the scope attribute in
<th> elements to specify if they are headers for columns, rows, or groups
of columns or rows.
<th scope="col">Name</th>
<th scope="col">Age</th>
Tables
Forms serve as the gateway between the user and the server, allowing
for dynamic, interactive web experiences. They are crucial for tasks such
as user authentication, data submission, feedback collection, and more.
Simply put, forms make websites more engaging and functional.
The <input> tag is commonly used to create form controls. The attributes
of this tag define the control's behavior.
<input type="" name="" value="">
The "type" attribute specifies the type of input control (e.g., text,
password, checkbox).
The "name" attribute is used for identifying the control, especially when
the data is sent to the server.
The "value" attribute sets a default value for the control, which the user
can overwrite.
THyperlinks
Images
<MAP name="mapname">
<AREA href="url" shape="rect" coords="x1,y1,x2,y2" alt="text">
<AREA href="url" shape="circle" coords="x,y,radius" alt="text">
<AREA href="url" shape="poly" coords="x1,y1,x2,y2,...xn,yn"
alt="text">
<AREA href="url" shape="default" alt="text">
</MAP>
rect → Rectangle
circle → Circle
poly → Polygon
default → Default shape
Frames