Vs codeis a source code editor (8)
Vs codeis a source code editor (8)
The process of communication between the client, browser, and server is as follows:
When we want to access any information on the internet, we search for it using a
web browser. The web browser retrieves the content from web servers, where it is
stored in the form of HTML documents.
An HTML document is created by writing code with specific tags in a code editor
of your choice. The document is then saved with the '.html' extension. Once
saved, the browser interprets the HTML document, reads it, and renders the web
page.
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.
A browser is an application that reads HTML documents and displays them as web
pages.
What is an HTML Document?
An HTML document is a text document saved with the '.html' or '.htm' extension,
containing text and specific tags enclosed in '< >
1. Parsing – Converts raw data into characters, tokens, and nodes, organizing
them into a DOM (Document Object Model) tree.
2. Rendering – The DOM tree is processed, styled, and displayed on the
screen.
The Backend
The backend, handles behind-the-scenes operations like storing and processing
data when users interact with the frontend. It uses languages like Python, Ruby,
and Java.
The Frontend
• Frontend refers to the visible part of a website or app that users interact
with, like the tables, images, and buttons. It's built using languages like
HTML, CSS, and JavaScript.
• HTML: The structure of a webpage.
• CSS: The style and design of the page.
• JavaScript: Adds interactivity and dynamic content to the website.
In essence, frontend is what users see, while backend manages the functionality.
File Organization
• For HTML: index.html
• For CSS: style.css
• For JavaScript: script.js
<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.
In this example, the <b> element (child) is nested inside the <h1> element
(parent).
HTML Attributes
HTML attributes are used to define the characteristics of an HTML element
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.
Core attributes are some of the most widely used attributes in HTML. There are
four main types:
• id
• class
• title
• Style
ID Attribute :
An ID is an attribute, a unique identifier assigned to only one HTML element within
a page. It is often used for unique styling and JavaScript manipulations.
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.
<head>
<style>
/* CSS rules go here */
p {
color: blue;
font-size: 18px;
}
. highlight {
background-color: yellow;
}
</style>
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 multi-line comment.
It spans multiple lines.
-->
CSS (Cascading Style Sheets) – Styling: It controls the design and layout of a
webpage.
Skeletal Tags
<!DOCTYPE html>: "Specifies the document type
<html> </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>).
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.
The <meta> tags in HTML provide metadata about the HTML document.
Metadata is data (information) about data. <meta> tags always go inside
the document's <head> tag and are typically used to specify the
character set, page description, keywords, author, and other metadata.
Below is an example HTML code snippet that includes various types of
<meta> tags commonly used:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8"> <!-- Character encoding -->
<meta name="viewport" content="width=device-width, initial-
scale=1.0"> <!-- Responsive design -->
<meta http-equiv="X-UA-Compatible" content="ie=edge"> <!--
Internet Explorer compatibility -->
<meta name="description" content="This is a description of the web
page"> <!-- Description for search engines -->
<meta name="keywords" content="HTML, CSS, JavaScript"> <!--
Keywords for search engines -->
<meta name="author" content="Your Name"> <!-- Author name -->
<title>Document</title>
</head>
<body>
<!-- Your content here -->
</body>
</html>
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
To create well-structured text in your HTML document, the <p> tag is essential for
defining paragraphs.
<p> </p>
<hr>
The <hr> tag is an empty or self-closing tag, meaning it doesn't require a closing
tag. It serves as a visual separator, dividing different sections of your document
with a horizontal line.
<br>
It's particularly useful in formatting textual content where line breaks are essential
for readability or visual layout. For instance, it can be used in addresses, poems, or
song lyrics to preserve the original line structure.
Anchor Tag
Links are fundamental to navigating the web. In HTML, links are created using the
<a> tag, also known as the Anchor tag.
Let's say you have a long webpage with multiple sections, and you want to create
a link at the top that, when clicked, takes the user directly to a specific section
further down the page. You can do this using HTML links that target specific
sections.
Image Tag
Images play a crucial role in enhancing web pages by providing a visual context
that complements textual content. In HTML, the <img> tag is used to embed
images into web pages.
Note: Styling dimensions and other properties are now more commonly managed
through CSS for better flexibility and maintainability.
1. none: This is the default value. It indicates that the browser should not
preload the audio file at all. The audio file will only start downloading
when the user initiates playback.
2. metadata: This value tells the browser to preload only the metadata of
the audio file, such as its duration and basic information about the
audio. This can be useful if you want to display the audio duration to
the user without fully loading the audio data.
3. auto: This value instructs the browser to preload the entire audio file
as much as possible without delaying the loading of other important
page content. The browser will try to load the audio file in the
background so that it's ready to play when the user decides to start it.
SVG in HTML
What is SVG?
SVG stands for Scalable Vector Graphics. Unlike raster images like PNGs
or JPGs, SVGs are not pixel-based. They're composed of vectors—
mathematical formulas that describe shapes, paths, and fills. This means
SVGs can be resized without losing quality.
Why Use SVG?
Scalability
File Size
SVG files are often smaller than their raster counterparts, especially for
simple shapes and icons.
Flexibility
.background {
background-image: url('image.svg');
}
SVG Attributes
Practical Examples
SVG can also be used to create more complex shapes like polygons,
lines, and text.
iFrames in HTML
What is an iFrame?
Basic Syntax
Attributes of iFrame
Practical Examples
<iframe src="https://www.youtube.com/embed/VIDEO_ID"
frameborder="0" allowfullscreen></iframe>
<iframe
src="https://maps.google.com/maps?q=LOCATION&output=embed"
frameborder="0"></iframe>
HTML Code Tag
The HTML <code> tag is a powerful element for displaying code snippets
within a webpage. It preserves both spaces and line breaks, making it
ideal for showcasing code. In this blog post, we'll explore how to use the
<code> tag effectively, especially in conjunction with Prism for code
highlighting.
What is the <code> Tag?
The <code> tag is a semantic HTML tag that's used for displaying code
snippets. It can be used both inline and within a block-level element like
<pre>.
Basic Usage
The most straightforward way to use the <code> tag is inline for short
code snippets:
<code>Your code here</code>
For multiline code snippets, it's common to combine the <code> tag with
the <pre> tag:
<pre><code>Your multiline code here</code></pre>
HTML Semantic Tags
Semantic tags add meaning to your HTML. They tell both the browser and
the developer what kind of content is being presented.
Here are some of the key semantic tags you must know about:
They enhance SEO, improve accessibility, and make your code easier to
read and maintain.
Examples
<header>
<h1>My Website</h1>
<nav>
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Services</a></li>
<li><a href="#">Contact</a></li>
</ul>
</nav>
</header>
<footer>
<p>Copyright 2023</p>
</footer>
Using the <article> and <section> tags
<article>
<h2>Article Title</h2>
<section>
<p>Content here</p>
</section>
</article>
<aside>
<p>This is an aside content</p>
</aside>
<nav>
<ul>
<li>Home</li>
<li>About</li>
</ul>
</nav>
<figure>
<img src="image.jpg" alt="An example image">
<figcaption>This is an example image.</figcaption>
</figure>
Conclusion
Using HTML's semantic tags can greatly benefit both your website's SEO
and the maintainability of your code. They offer a way to structure your
HTML in a meaningful manner, making your website more accessible and
easier to understand.
HTML Canvas
The <canvas> element in HTML is a powerful feature for rendering
graphics and shapes directly within web pages. Though it's often paired
with JavaScript for dynamic rendering, the canvas itself is an HTML
element. In this blog, we'll explore what you can do with the <canvas>
element alone.
What is Canvas?
Here are some reasons why you might use the <canvas> element:
• Graphics: For drawing shapes, graphs, and other visual
representations.
• Dynamic Content: To dynamically update visual elements.
• Interactivity: Though this involves JavaScript, the canvas element is
the foundation for interactive graphical content.
Basic Syntax
Attributes of Canvas
You can also style the <canvas> element with CSS. For example, to add a
border:
canvas {
border: 1px solid black;
}
Obsolete HTML Tags
Obsolete tags are HTML elements that are no longer recommended for
use. They may lack support in modern browsers and are likely to be
phased out entirely in future versions of HTML.
Modern Alternatives
It's better to use CSS for styling and layout as it separates content from
presentation.
Replacing <font>
Replacing <center>
Replacing <u>
Conclusion
Understanding obsolete HTML tags is not just a trip down memory lane; it
also emphasizes the importance of keeping up to date with the latest
web standards. Always opt for modern, semantic HTML and CSS for
styling to ensure your websites are future-proof.
Character Sets
Why is it Important?
The character set is generally specified using the <meta> tag within the
<head> section of an HTML document
<meta charset="UTF-8">
Examples
Using UTF-8
<meta charset="UTF-8">
Using ISO-8859-1
Conclusion
HTML elements are generally divided into two categories: Block-level and Inline
elements.
1. Do not start on a new line and are part of the flow of surrounding content.
2. Take up only as much width as needed based on their content.
3. Can contain other inline elements, but should not contain block-level
elements (like <div> or <p>).
List Tags
1. Unordered list.
<ul>
<li>Pen</li>
<li>Pencil</li>
<li>Eraser</li>
</ul>
2. ordered list.
<ol>
<li>Pen</li>
<li>Pencil</li>
<li>Eraser</li>
</ol>
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>
<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
<TABLE>...</TABLE> → Table definition
<TABLE width="x%"> → Table width in percentage
<TABLE width=x> → Table width in pixels
<TABLE border=x> → Border thickness
<TABLE cellpadding=x> → Space between border and text
<TABLE cellspacing=x> → Space between cells
Table Rows & Cells
Text Input
The text input type is the most basic form of input and is widely used for
collecting simple text data.
<input type="text" name="username" placeholder="Enter your
username">
In the above example, the placeholder attribute provides a hint to the
user about what to enter.
Password Input
The password input type is similar to the text type but hides the
characters entered by the user for security reasons.
<input type="password" name="password" placeholder="Enter your
password">
Radio Buttons
Radio buttons are used when you want the user to select only one option
from a set of choices.
<input type="radio" id="male" name="gender" value="male">
<label for="male">Male</label>
<input type="radio" id="female" name="gender" value="female">
<label for="female">Female</label>
Checkbox
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.
Textarea & Select
These elements allow for more complex data collection and provide a
better user experience.
The textarea element is used when you need multiline text input from the
user. This is particularly useful for comments, reviews, or any other type of
input where the length is unpredictable.
<textarea name="comment" rows="4" cols="50">
Enter your comment here...
</textarea>
The rows and cols attributes define the visible dimensions of the textarea.
The select element creates a dropdown menu for the user. It is useful
when you have a predefined list of options for the user to choose from.
<select name="fruits">
<option value="apple">Apple</option>
<option value="banana">Banana</option>
<option value="cherry">Cherry</option>
</select>
Each option inside the select tag represents an item in the dropdown
list.
action
The action attribute specifies the URL where the form data should be sent
after submission.
<form action="/submit.php" method="POST">
</form>
method
The method attribute defines how data is sent. The two most common
methods are GET and POST.
<form action="/submit.php" method="POST">
</form>
name
The name attribute specifies the name for the form element, making it
easier to reference in scripts or the server-side code.
<input type="text" name="username">
placeholder
This attribute provides a hint to the user as to what can be entered in the
field.
<input type="text" placeholder="Enter your username">
required
required
pattern
The pattern attribute specifies a regular expression that the input must
match to be valid.
<input type="text" pattern="[a-zA-Z0-9]+">
THyperlinks
• <A href="http://...">...</A> → External link to a webpage
• <A href="mailto:email@example.com">...</A> → Email link
• <A href="file.html">...</A> → Link to a local page in the same folder
• <A name="xyz">...</A> → Anchor definition
• <A href="#xyz">...</A> → Link to an anchor in the same file
• <A href="file.html#xyz">...</A> → Link to an anchor in another file
Images
• <IMG src="imageURL"> → Inserts an image (GIF, JPG, PNG)
• <IMG ... width=x height=y> → Scales the image (in pixels)
• <IMG ... border=x> → Defines the image border thickness
• <IMG ... alt="text"> → Alternative text when image is not displayed
• <IMG ... align=valign> → Aligns image relative to text line
• <IMG ... align=halign> → Aligns text around image (left, right)
• <IMG ... hspace=x> → Horizontal spacing around the image
• <IMG ... vspace=y> → Vertical spacing around the image
• <IMG ... usemap=#map> → Uses an image map
• Image Map
<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