No. HTML elements are defined by a starting tag, may contain some content and a closing tag.For example, <h1>Heading 1</h1> is a HTML element but just <h1> is a starting tag and </h1> is a closing tag.
No. HTML elements are defined by a starting tag, may contain some content and a closing tag.For example, <h1>Heading 1</h1> is a HTML element but just <h1> is a starting tag and </h1> is a closing tag.
Tags are the primary component of the HTML that defines how the content will be structured/ formatted, whereas Attributes are used along with the HTML tags to define the characteristics of the element. For example, <p align=” center”>Interview questions</p>, in this the ‘align’ is the attribute using which we will align the paragraph to show in the center of the view.
HTML elements which do not have closing tags or do not need to be closed are Void elements. For Example <br />, <img />, <hr />, etc.
In HTML, a blank sequence of whitespace characters is treated as a single space character, Because the browser collapses multiple spaces into a single space character and this helps a developer to indent lines of text without worrying about multiple spaces and maintain readability and understandability of HTML codes.
In HTML some characters are reserved like ‘<’, ‘>’, ‘/’, etc. To use these characters in our webpage we need to use the character entities called HTML Entities. Below are a few mapping between the reserved character and its respective entity character to be used.
Character | Entity Name | Entity Number |
---|---|---|
< | < | < |
> | > | > |
& | & | & |
(non-breaking space) Eg. 10 PM | Eg. <p>10  PM</p> |   |
The class attribute is used to specify the class name for an HTML element. Multiple elements in HTML can have the same class value. Also, it is mainly used to associate the styles written in the stylesheet with the HTML elements.
Multiple elements in HTML can have the same class value, whereas a value of id attribute of one element cannot be associated with another HTML element.
Multipart form data is one of the values of the enctype attribute. It is used to send the file data to the server-side for processing. The other valid values of the enctype attribute are text/plain and application/x-www-form-urlencoded.
Every web page has different components to display the intended content and a specific UI. But still, there are few things which are templated and are globally accepted way to structure the web page, such as:
To optimize website load time we need to optimize its asset loading and for that:
HTML has various formatting tags:
The three kinds of Doctypes which are available:
The character set is defined in <meta> tag inside <head> element.
<!DOCTYPE>
<html>
<
head>
<
meta
charset=
"UTF-8">
</
head>
</
html>
The effect on a normal webpage of the tags <strong>, <b> and <em>, <i> is the same. <b> and <i> tags stands for bold and italic. These two tags only apply font styling and bold tag <b>, just adds more ink to the text, these tags don't say anything about the text.
Whereas, <strong> and <em> tags represent that the span of text is of strong importance or more importance and emphatic stress respectively than the rest of the text. These tags have semantic meaning.
<head> tag provides the information about the document. It should always be enclosed in the <html> tag. This tag contains the metadata about the webpage and the tags which are enclosed by head tag like <link>, <meta>, <style>, <script>, etc. are not displayed on the web page. Also, there can be only 1 <head> tag in the entire Html document and will always be before the <body> tag.
<body> tag defines the body of the HTML document. It should always be enclosed in the <html> tag. All the contents which needs to be displayed on the web page like images, text, audio, video, contents, using elements like <p>, <img>, <audio>, <heading>, <video>, <div>, etc. will always be enclosed by the <body> tag. Also, there can be only 1 body element in an HTML document and will always be after the <head> tag.
Yes, we can display a web page inside another HTML web page. HTML provides a tag <iframe> using which we can achieve this functionality.
<
iframe
src=
”url
of
the
web
page
to
embed” />
Cell Spacing is the space or gap between two consecutive cells. Whereas, Cell Padding is the space or gap between the text/ content of the cell and the edge/ border of the cell. Please refer to the above figure example to find the difference.
HTML provides two table attributes “rowspan” and “colspan” to make a cell span to multiple rows and columns respectively.
Yes, it is possible using the “display” property with its value as “block”, to change the inline element into a block-level element.
There are mainly 7 values of position attribute that can be used to position an HTML element:
Below are some of the display types which are rarely used:
HTML provides a hyperlink - <a> tag to specify the links in a webpage. The ‘href’ attribute is used to specify the link and the ‘target’ attribute is used to specify, where do we want to open the linked document. The ‘target’ attribute can have the following values:
There are three ways in which we can specify the styles for HTML elements:
The anchor tag <a> is used to create a hyperlink to another webpage or to a certain part of the webpage and these links are clickable, whereas, link tag <link> defines a link between a document and an external resource and these are not clickable.
HTML provides a <script> tag using which we can run the javascript code and make our HTML page more dynamic.
<!DOCTYPE
html>
<
html>
<
body>
<
h1>
<
span>
This is a demo for
</
span>
<
u>
<
span
id=
"demo">
</
span>
</
u>
</
h1>
<
script>
document.getElementById(
"demo").innerHTML =
"script Tag"
</
script>
</
body>
</
html>
If the scripts contain some event-triggered functions or jquery library then we should use them in the head section. If the script writes the content on the page or is not inside a function then it should be placed inside the body section at the bottom. In short, follow below three points:
The HTML form is used to collect the user inputs. HTML provides a <form> tag to create forms. To take input from the user we use the <input> tag inside the form so that all collected user data can be sent to the server for processing. There are different input types like ‘button’, ‘checkbox’, ‘number’, ‘text’, ‘password’, ‘submit’ etc.
<
form
action=
"/submit_data.php">
<
label>
Enter your name:
</
label>
<
input
type=
"text"
name=
"name" />
<
label>
Enter Mobile number
</
label>
<
input
type=
"number"
name=
"mobile_no"/>
<
input
type=
"submit"
value=
"Submit">
</
form>
HTML allows event trigger actions in browsers using javascript or JQuery. There are a lot of events like ‘onclick’, ‘ondrag’, ‘onchange’, etc.
<!DOCTYPE
html>
<
html>
<
body
style=
"padding-top:50px">
<
h3
id=
"event_demo">
0
</
h3>
<
input
type=
"button"
onclick=
"myFunction()"
value=
"Click Me" />
<
input
type=
"reset"
onclick=
"reset()"
value=
"Reset" />
</
body>
<
script>
function
myFunction(
)
{
var value =
document.getElementById(
"event_demo").innerHTML
value =
parseInt(value) +
1;
document.getElementById(
"event_demo").innerHTML = value;
}
function
reset(
)
{
document.getElementById(
"event_demo").innerHTML =
0;
}
</
script>
</
html>
No. There are some HTML tags that don't need a closing tag. For example: <image> tag, <br> tag. More details.
Semantic HTML is a coding style. It is the use of HTML markup to reinforce the semantics or meaning of the content. For example: In semantic HTML <b> </b> tag is not used for bold statement as well as <i> </i> tag is used for italic. Instead of these we use <strong></strong> and <em></em> tags.