HTML & CSS I Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

What is semantic?

A

Semantic refers to the meaning or significance of something. In the context of web development and HTML,** semantic relates to the meaning and structur**e that HTML tags provide to a web page. A semantic HTML tag describes its content both to the browser and the developer in a meaningful way, making it clear what role that content plays on the page. This helps in improving accessibility, SEO, and maintainability of the code.

header, footer, nav, article, main, section, aside, h1-h6

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a purpose of semantics?

A

For example, instead of using a generic <div> or <span>, which have no inherent meaning, you can use semantic tags like <header>, <article>, or <footer> to clearly define parts of your document.</span>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Span<> vs div<> long version

A

The primary difference between <div> and <span> elements in HTML lies in their semantic meaning and their intended use within the structure of a webpage</span>

<div> (block-level element):
The <**div**> element is a **block-level container** meaning it takes up the **full width available**, **stacking content vertically** (one block after another).

Block-level elements always **start on a new line.**
It’s often used to **group larger chunks of conten**t, such as sections, articles, or multiple paragraphs.

<**span**> (inline-level element):
The <span> element is an i**nline-level container,** meaning it takes up only **as much width as its content requires.** **It doesn’t force content onto a new line.**
Inline elements appear within a line of text or other inline elements.
**It’s typically used to apply styling or scripting to a part of the content without affecting the layout of other elements.**
</span></div>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Span<> vs div<> in Summary

A

<div>: Block-level, used for grouping larger content, takes up the full width, starts on a new line.

<span>: Inline-level, used for styling or grouping smaller parts of content, takes up only as much width as needed, remains in line with surrounding text.

Both <div> and <span> are non-semantic elements, meaning they don’t provide any inherent meaning to the content (unlike <header>, <article>, etc.), but they’re useful for structuring and styling content.
</article></header></span></div></span></div>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Inline styles

A

Inline styles in HTML refer to CSS styles that are applied directly to individual HTML elements using the style attribute. This allows you to apply specific styles to a single element without needing to create a separate CSS class or stylesheet.

most precise, most important, directly on tag

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Characteristics of Inline Styles

A

Specificity: Inline styles have a higher specificity than styles defined in external stylesheets or <style> blocks. This means they will usually take precedence over those styles unless there are other styles that are marked as !important.</style>

Immediate Effect: Styles are applied immediately to the element they are attached to, allowing for quick adjustments without needing to edit external files.

Limited Scope: Inline styles only apply to the element in which they are defined. They cannot be reused across multiple elements, which can lead to code duplication if the same styles are needed for several elements.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Specificity

A

Specificity in CSS refers to the set of** rules that determines which styles are applied to an element when there are conflicting CSS rules.**

It is a hierarchical mechanism that helps browsers decide which CSS rules take precedence over others. Understanding specificity is crucial for writing efficient and maintainable CSS.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Specificity Calculation

A
  1. Inline styles:

Example: <p style="color: red;">
Specificity: 1, 0, 0, 0 (a=1, b=0, c=0, d=0)

2.ID selectors:
Example: #header { color: blue; }
Specificity: 0, 1, 0, 0 (a=0, b=1, c=0, d=0)

3.Class selectors:
Example: .menu { color: green; }
Specificity: 0, 0, 1, 0 (a=0, b=0, c=1, d=0)

4.Type selectors:
Example: div { color: yellow; }
Specificity: 0, 0, 0, 1 (a=0, b=0, c=0, d=1)

  1. Combined selectors:
    Example: div.menu#header { color: purple; }
    Specificity: 0, 1, 1, 1 (a=0, b=1, c=1, d=1)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the difference between display: none and visibility: hidden?

A

display: none;

Removes the Element from the Document Flow: When an element is set to display: none;, it is completely removed from the layout of the page. This means that the space it occupied is also removed, and other elements will move to fill that space.

->The element **is not rendered in the page at all. **As a result, it is not interactive; users cannot click on it, and it cannot receive any events (e.g., hover, focus, etc.).

visibility: hidden;

Hides the Element but Maintains Space: When an element is set to visibility: hidden;, it remains in the layout of the page, but it is invisible.** The space it occupies is still accounted for, meaning that other elements do not shift to fill that space.**

-> The element remains part of the document flow and can still receive events, even though it is not visible. For instance, users can still tab through the element if it is focusable (like a button or link).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is CSS preprocessor and what is it used for?

A

A CSS preprocessor is a scripting language that extends CSS with additional features, allowing developers to write more maintainable, modular, and efficient stylesheets. CSS preprocessors add functionality to CSS through features such as variables, nested rules, mixins, and functions, which are not available in standard CSS. After the code is written in the preprocessor’s syntax, it is compiled into standard CSS that browsers can understand.

Sass (Syntactically Awesome Style Sheets):

Variables
Nesting
Mixins
Partials and Imports

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is doctype? Why do u need it?

A

doctype is an instruction to the browser to inform about the version of html document and how browser should render it.

It ensures how element should be displayed on the page by most of the browser. And it also makes browser’s life easier. otherwise, browser will guess and will go to quirks mode. Moreover, doctype is required to validate markup.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the use of data- attribute?

A

allow you to store extra information/ data in the DOM. u can write valid html with embedded private data. You can easily access data attribute by using javascript and hence a lot of libraries like knockout uses it.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How can u highlight text in html?

A

use mark element.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Can u apply css rule to a part of html document?

A

Yes. by using “scopped” in the style tag.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What are optional closing tag? and why would u use it?

A

p, li, td, tr, th, html, body, etc. you don’t have to provide end tag.

Whenever browser hits a new tag it automatically ends the previous tag. However, you have to be careful to escape it.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Span vs div- what is illegal

A

div is a block element and span is inline element.

It is illegal to put block element inside inline element. div can have a p tag and a p tag can have a span. However, span can’t have a div or p tag inside.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

When should you use section, div or article?

A

<section>, group of content inside is related to a single theme, and should appear as an entry in an outline of the page. It’s a chunk of related content, like a subsection of a long article, a major part of the page (eg the news section on the homepage), or a page in a webapp’s tabbed interface. A section normally has a heading (title) and maybe a footer too.

<article>, represents a complete, or self-contained, composition in a document, page, application, or site and that is, in principle, independently distributable or reusable, e.g. in syndication. This could be a forum post, a magazine or newspaper article, a blog entry, a user-submitted comment, an interactive widget or gadget, or any other independent item of content.

<div>, on the other hand, does not convey any meaning, aside from any found in its class, lang and title attributes.
</div></article></section>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What are the difference between svg and canvas

A

SVG: vector based, Better for static graphics, Better support for accessibility, Logos, icons, charts, animations

Canvas: Bitmap-based, pixel based, Requires manual state management, Less accessible

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What is the difference between <strong><em> and <b><i> tags?</i></b></em></strong>

A

<strong> and <em>:</em></strong>

These tags provide information about the importance or emphasis of text to screen readers, making them more accessible for users with disabilities. Screen readers may announce text within <strong> as “strong” and within <em> as “emphasized.”
<b> and <i>:</i></b></em></strong>

Since these tags are purely presentational, they do not convey any additional information to assistive technologies, making them less accessible. Text styled with <b> and <i> is visually bold and italicized, respectively, but it lacks semantic meaning.</i></b>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What are the new DocType and Charset in HTML5?

A

The DocType element communicates the HTML version to the browser. It usually appears in the first line of code of an HTML page. Unlike the earlier versions/standards of HTML, DocType has a simplified format in HTML5.

The CharSet is a new meta tag attribute in HTML5 that configures the character encoding.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What all new Form elements were introduced in HTML

A

Here is the list of new form elements available in HTML5.

<datalist> – It specifies a list of options for input controls.
<keygen></keygen> – This tag generates an encryption key.
<output> – It defines the result of an expression.
</output></datalist>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

What are various elements that provide better structuring in HTML5?

A

<article> – This element allows specifying an article.
<aside> – It allows you to view content other than the page content.
<bdi> – It lets a part of the text get formatted in a different direction from other text.
<command></command> – It displays a button element that processes a command upon user action.
<details> – It adds additional details that a user can show or hide.
<dialog> – It initializes a dialog box or popup window.
<figure> – This element can show illustrations, diagrams, photos, and code listings.
<figcaption> – It adds a caption for the image specified by an <figure> element.
<footer> – This tag appends a footer to a document.
<header> – This tag inserts a header into a document.
<hgroup> – If a page includes multiple headings, then this tag groups them into a set of <h1> to <h6> elements.
</h6></h1></hgroup></header></footer></figure></figcaption></figure></dialog></details></bdi></aside></article>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

Q-3. Which of the HTML5 elements supports media content?

A

<audio> – It specifies sound content.
<video> – It links to a video.
<source></source> – This tag specified the source of video and audio links.
<embed></embed> – It acts as a container for external applications.
<track></track> – This element defines tracks for video and audio.
</video></audio>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

What is SVG and why do you use it?

A

SVG is an acronym for Scalable Vector Graphics as recommended by W3C.

Its purpose is to display vector-based graphics over the Web.
The graphics use an XML format.
SVG graphics are of higher quality and do not lose it even when resized.
All elements and attributes of SVG support animation.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

What does Canvas mean in HTML? And what is its default border size?

A

Canvas is an HTML5 element that can draw graphics on the fly with the help of JavaScript. The <canvas> element can only contain graphics. It supports a number of methods for drawing paths, boxes, circles, text, and images.</canvas>

By default, It has no border. However, it allows the use of CSS to change the border style.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

How does Canvas differ from SVG?

A

Here are a few points elaborating on the differences between Canvas and SVG.

Canvas depends on the resolution whereas SVG doesn’t.
It does not allow event handlers whereas SVG does provide support for event handlers.
Canvas is ideal for graphics-intensive games whereas SVG doesn’t intend for gaming.
It works well for small rendering areas whereas SVG may perform better for large rendering areas like Google Maps.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

Does HTML5 provide drag and drop facility? How do you set an image as draggable?

A

To set an image as draggable, initialize the draggable attribute with true.

<img></img>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

What is HTML5 Web Storage?

A

HTML5 brought this new ability to store web pages within the browser cache. This web store is not only faster than the cookies but secured too. It is capable of storing a large amount of data without compromising the performance of the website.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q

What is the difference between localStorage and sessionStorage objects?

A

The following points describe the differences between the localStorage and sessionStorage objects.

The <localStorage> object **doesn’t have an expiry for the stored data** whereas the <sessionStorage> object **keeps it only for a single session**.</sessionStorage></localStorage>

The <localStorage> object doesn’t have a provision to delete the data upon closing of the browser window whereas the <sessionStorage> **object clears it simultaneously with the window closing down**.</sessionStorage></localStorage>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q

What are the elements of the CSS Box Model?

A

The CSS box model defines the layout and design of CSS elements. The elements are content (like text and images, padding (the area around content), border (the area around padding), and margin (the area around the border).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
31
Q

How can CSS be integrated into an HTML page?

A

There are three ways of integrating CSS into HTML: using style tags in the head section

, using inline-styling,

writing CSS in a separate file, and linking into the HTML page by the link tag.

32
Q

Define z-index.

A

Z-index is used to specify the stack order of elements that overlap each other. Its default value is zero and can take both negative and positive values. A higher z-index value is stacked above the lower index element. It takes the following values- auto, number, initial, and inherit.

33
Q

What are the benefits of CSS Sprites?

A

With CSS sprites, loading multiple images is not an issue.

Blinking is not seen.
Advanced downloading of assets does not take place until needed

34
Q

How can you target h3 and h2 with the same styling?

A

Multiple elements can be targeted by separating with a comma:

h2, h3 {color: red;}

35
Q

What are the limitations of CSS?

A

CSS cannot always assure compatibility with every browser; you need to be cautious while choosing the style selector.

The parent selector tag is not available, thus you can’t select the parent selector tag.

Some selectors can lead to cross-browser issues due to their less browser-friendly behavior.

We cannot request a webpage through CSS.

36
Q

What are the different types of Selectors in CSS?

A

Universal Selector, Element type Selector, ID selector, Class selector, Descendant combinatory, Child Combinator, General Sibling Combinator, Adjacent sibling combinator, and Attribute selector.

37
Q

What is a CSS Preprocessor? What are Sass, Less, and Stylus? Why do people use them?

A

CSS preprocessor is a tool used to enhance the basic functionality and let us use the complex logical syntax such as variables, functions, mixins, and code nesting within vanilla CSS scripts themselves.

Sass (Syntactically Awesome Style Sheets) uses .sass extension. It is used for indentation; it doesn’t use semicolons or curly brackets.

Less (Leener Stylesheets) uses .less extension. It is easy to add to any JavaScript Project by using NPM or less.js file. Here, @ is used to define the variables.

Stylus provides great flexibility in writing syntax. It is able to use native CSS as well as the exclusion of brackets, colons, and semicolons. There is no need to use @ or $ to define the variables.

People use SASS, LESS, and Stylus in order to extend the basic functionality of vanilla CSS

38
Q

What is VH/VW (viewport height/ viewport width) in CSS?

A

VH and VW are CSS units used to measure viewport height and viewport width respectively in percentage form in the responsive design techniques. E.g. If the height of the browser is 1000px, then VH is 1/100 of the height of the viewport that is 1000px*(1/100) = 10px, which is the height of the browser. The same applies to VW (viewport width).

39
Q

Difference between reset vs normalize CSS? How do they differ?

A

Reset CSS is used to remove all built-in styles in the browser such as paddings, margins, and font sizes, and can be reset using all the elements.

Normalize CSS is used to make all built-in styles in the browser consistent and correct bugs as per varying browsers.

40
Q

What is the difference between inline, inline-block, and block?

A

Block Elements are <div> and <p>. They usually start on a new line and can take space for an entire row or width.

Inline elements are <a>, <span>, <strong>, and <img></img> tags. They don’t start on a new line. However, they appear on the same line as the content and tags beside them.</strong></span></a>

Inline block elements have padding and margins and set height and width values. Though, they are similar to inline elements.

41
Q

What are Pseudo classes?

A

Pseudo-classes are the type of pseudo-elements that don’t exist in a normal document tree. It allows selecting the regular elements under certain conditions especially when we try to hover over the link; the anchor tags are
:link, :visited, :hover, :active, :focus

42
Q

How do you specify units in the CSS? What are the different ways to do it?

A

There are mainly four different units in the CSS that are px, em, pt, and percentage (%).

Px (Pixel) is used for fine-grained control and alignment and not cascade. To get it sharp, we can use 1px or multiple of px.

Em is used to maintain relative size and responsive fonts. 1em = 16px having also the same font size. It is advisable to set the font size to 10px in common practice.

Pt (point) is a fixed-size unit that is used in print. 1pt = 1/72 inch.

Percentage (%) is used to set the font size with respect to the font size of the body. Thus, it is necessary to set the reasonable font size of the body.

43
Q

Adaptive Design

A

Main focus is to develop a website in multiple fixed layout sizes.

Offers good control over the design to develop variation in screens.

It is very time-consuming and takes a lot of effort to build the best possible adaptive design as examining it will need to go for many options with respect to the realities of the end user.

There are six standard screen sizes for the appropriate layouts; they are 320px, 480px, 760px, 960px, 1200px, 1600px to design.

44
Q

Responsive Design

A

Main focus is to show content with respect to browser space.

Offers less control over the design.

It takes less time to build the design and there is no screen size issue irrespective of content.

It uses CSS media queries to design the screen layouts with respect to specific devices and property changes in the screen.

45
Q

How is the border-box different from the content box?

A

Border-box consists of properties such as content, padding, and the border with respect to height and width.

However, Content-box is a default value property used for the box-sizing as well as it helps to add border and padding to give proper height and width to the box without having a border and padding properties.

46
Q

How is opacity specified in CSS3?

A

Opacity is the measure of content transparency. It is measured in the range from 0 to 1. Value 1 means the content is completely opaque. It is not supportable in the internet browser. Also, the 60% of opacity is applicable in the div section where we need to apply the filter property (polyfill) to make it completely opaque.

47
Q

What is cascading in CSS?

A

Cascading is defined as the process of style declaration and its weight that will help the browser in selecting the styling rules with respect to time.

48
Q

When does DOM reflow occur?

A

DOM reflow occurs when you insert, move, update, remove, and animate the elements in the DOM as well as when you modify content on the page and change style.

49
Q

What is the grid system?

A

The CSS grid system is a type of powerful layout of 2 dimensional systems with respect to columns and rows.

50
Q

What are the different ways to hide the element using CSS?

A

display: none, visibility: hidden, position: absolute

51
Q

What does Accessibility (a11y) mean?

A

Accessibility is to make the system accessible in such a manner that the website should have the text-to-speech capability, for people with physical disabilities, designed with the help of software or hardware combinations.

52
Q

Difference between CSS grid vs flexbox?0

A

CSS Grid Layout is a two-dimensional system along with rows and columns. It is used for large-sized layouts.

Flexbox is a Grid layout with a one-dimensional system either within a row or a column. It is used for the components of an application.

53
Q

How do I restore the default value of a property?

A

keyword “initial” is used to restore the default value of a property.

54
Q

What is the difference between CSS variables and pre-processor (SASS, LESS, Stylus) variables?

A

CSS variables don’t need a pre-processor. It is cascaded, accessed, and manipulated in JavaScript.

Preprocessor variables don’t cascade.

55
Q

What does * { box-sizing: border-box; } do? What are its advantages?

A

Box-sizing: border-box is used to provide the inner dimension for the elements in the document by providing padding and border with respect to the height and width of the content.

56
Q

What does !important mean in CSS?

A

The style “!important” in the CSS has the highest precedence. Also, the cascaded property will be overridden with it.

57
Q

What is progressive rendering? How do you implement progressive rendering on the website? What are its advantages?

A

Progressive rendering is the process of improving the performance of a webpage with respect to loading time in order to display the content speedily. The use of loading the lazy loading of the image with the help of Intersection Observer API via viewport.

58
Q

How does absolute positioning work?

A

Absolute positioning is used to place the element which is then removed from the HTML document from the normal workflow without creating any space for the element in the HTML page layout. The element can be positioned respectively to the closest positioned ancestor; otherwise, if the ancestor is not found, the element is placed with respect to the initial container box. The values provided to the top, right, left and bottom determine the final position of the element.

59
Q

Does this property work overflow: hidden?

A

Overflow: the hidden property is used to specify the content’s clipping. We need to add scrollbars to the content area at the time of specified container size exceeding the content limit where the content gets enclosed. This makes the content invisible via clipping; also the overflow value will be hidden.

60
Q

When should you use translate () instead of absolute positioning?

A

Translate is a CSS transform value. On changing opacity or transform, browser reflow or repaint is not triggered. Transform requires the browser to create a GPU layer for elements but using the CPU changes absolutes positioning properties. Translate () is more efficient and results in shorter paint times. On using translate (), element occupies original space, unlike in changing absolute positioning.

61
Q

Name different ways to position some aspects in CSS.

A

The positioning property specifies the positioning method type. The five different position values are fixed, static, absolute, sticky, and relative. The elements are positioned using top, left, right, and bottom properties. These properties need to be set first, and they work depending on position value.

62
Q

What are mixins?

A

A mixin is similar to a function block of code returning a single value—mixin output lines of Sass code that directly compiles into CSS styles. At the same time, the function returns a value that becomes the value for a CSS property or something that can be passed to another mixin.

63
Q

How can you optimize the webpage for prints?

A

Identify and control ‘content areas’ of the website. A website generally has a footer, header, sidebar, navbar, and main content area. Most of the work is done by controlling the content area. So, conquer print media without changing the website’s integrity by using page breaks, creating a stylesheet for print, size your page for print, and avoid unnecessary HTML tables.

64
Q

What is meant by CSS working under the hood?

A

When a browser displays a document, it combines style information and document content. The document is processed in two stages:

Conversion of HTML and CSS into Document Object Model

DOM displays contents of browser

65
Q

Tell us about CSS float property.

A

The float property of CSS positions an image to the right or left as needed, including text wrapping around it. All properties of elements used before it remain unchanged.

66
Q

What do you understand by pseudo-elements?

A

Pseudo-elements provide special effects to some selectors. CSS finds use in applying styles in HTML markups. If additional markup or style is not feasible for a document, the pseudo-elements help by allowing extra markup without interfering with the original document.

67
Q

Differentiate between logical and physical tags

A

Logical tags mainly focus on content and are older as compared to physical ones. Logical ones do not find much usage in presentation and terms of aesthetics. At the same time, physical ones find application in presentation.

68
Q

Tell us something about CSS3.

A

CSS3 is divided into modules and is supported by almost every browser. Many graphics-related characteristics are introduced in CSS3 like box-shadow, Border-radius, and flexbox. A user can create precise multiple background images using properties like background-position, background-repeat, and background-image styles.

69
Q

How is a CSS selector used?

A

With a CSS selector, we can choose the content we want to style to bridge between HTML files and style sheets. CSS selector syntax is “select” HTML elements created on their class, id, type, etc.

70
Q

What are CSS image scripts?

A

A group of images placed into one image is a CSS image script. It can reduce load time and project multiple images into a single web page

71
Q

Explain CSS specificity.

A

CSS specificity is a rank or score that decides style declaration to be used to an element.

ID selectors have high specificity, while universal selector * has low specificity. The four CSS categories that authorize the selector’s specificity level are IDs, inline style, elements/pseudo-elements, and classes and attributes.

72
Q

Define gradients in CSS.

A

A property of CSS that allows displaying smooth transformation between two or more specified colors. The types of gradients are linear and radial.

73
Q

What are the properties of flexbox?

A

The properties of flexbox are

flex
-direction,
-wrap,
-flow,
-content,
-and align-items, and content.

74
Q

Tell us about the use of the CSS Box Model.

A

The CSS Box model is a box binding HTML element that includes padding, border, margin, and the actual content. With the box model, we get the authority to add a border all around elements and define space between elements.

75
Q

What are the position states in CSS?

A

The four-position states in CSS are relative, static, absolute, and fixed. The default position state is static.

76
Q

Differentiate between absolute and relative in CSS.

A

The main difference is that relative is used for the same tag in CSS. If we write right:20 px, then padding shifts 20 px in the right. Whereas absolute is relative to the non-static parent, i.e., if we write right:20 px, the result will be 20 px far from the right edge of the parent element.