Index

HTML

  1. What is semantic HTML?
  2. How to create a nested webpage in HTML?
  3. Why is a URL encoded in HTML?
  4. What is SVG?
  5. What is the difference between progress and meter tag?
  6. Do all character entities display properly on all systems?
  7. What is the advantage of collapsing white space?
  8. How do you create links to sections within the same page?
  9. What is the use of alternative text in image mapping?
  10. If the user’s operating system does not support the needed character, how can the symbol be represented?
  11. Why are there both numerical and named character entity values?
  12. What if there is no text between the tags or if a text was omitted by mistake? Will it affect the display of the HTML file?
  13. What are the limits of the text field size?
  14. How are active links different from normal links?
  15. What happens if you open the external CSS file in a browser?
  16. Do you know which are two semantic tags are included in HTML5 version?
  17. What is the Application Cache in HTML5 and why it is used?
  18. What are the tags used to separate a section of texts?
  19. What is the difference between DIV and SPAN in HTML?
  20. Is there any way to keep list elements straight in an HTML file?
  21. Explain The Key Differences Between LocalStorage And SessionStorage Objects.
  22. What is the relationship between the border and rule attributes?
  23. What is difference between HTML and XHTML?
  24. What would happen if the HTML Document does not contain <!DOCTYPE>?
  25. What are some of the key new features in HTML5?
  26. What are “web workers”?
  27. What is the Geolocation API in HTML5?
  28. What’s one main result if you do not specify a doctype in an HTML page?
  29. What’s the difference between ‘block’ and ‘inline’ elements?
  30. How would you group form elements?
  31. Should you collapse white spaces?
  32. What are applets?
  33. How we use JavaScript with HTML?
  34. What are the web sockets?
  35. What do you mean by Box Model?
  36. What is the meaning of markup in HTML?
  37. How Do I Specify A Specific Combination Of Frames Instead Of The Default Document?
  38. Why Aren't My Frames The Exact Size I Specified?
  39. Is It Possible To Make The Html Source Not Viewable?
  40. Explain Vbscript
  41. How do I make a form so it can be submitted by the hitting ENTER?
  42. What is shadow DOM?

Advanced HTML

  1. How is data stored in HTML5?
  2. A portion of a text seems to climb out of the page boundaries. Why is that?

jQuery

  1. What are the advantage of using jQuery?
  2. Difference between ID selector and class selector in jQuery?
  3. What is main advantage of loading jQuery library using CDN?

CSS

  1. How do CSS precedence/cascading rules work? How does the !important directive affect the rules?
  2. How Do I Design For Backward Compatibility Using Style Sheets?
  3. What Can Be Done With Style Sheets That Can Not Be Accomplished With Regular Html?
  4. Why Shouldn't I Use Fixed Sized Fonts ?
  5. What are the benefits of CSS sprites?
  6. What is tweening?
  7. What are the merits and demerits of embedded style sheets?
  8. What does CSS selector mean?
  9. What is contextual selector?
  10. What is graceful degradation?
  11. What is progressive enhancement?
  12. What is Alternate Style Sheet?
  13. How can CSS be cascaded to mix with user’s personal sheet?
  14. How does the Z index function?
  15. What is CSS specificity?
  16. Why background and color are the separate properties if they should always be set together?
  17. What is the use of ruleset?
  18. Do you use any CSS preprocessors, and which do you prefer?
  19. What are web safe fonts and fallback fonts?
  20. What are pseudo elements and what are they used for?
  21. What are the disadvantages of using CSS?
  22. Explain the CSS Box Model and its different elements.
  23. What is the float property used for in CSS?
  24. Explain the difference in approach when designing a responsive website over a mobile-first strategy?
  25. What are the advantages and disadvantages of using a CSS pre-processor??
  26. How would you implement the basic layout components of the box model in CSS? Give an example.
  27. How do you define a pseudo class in CSS? What are they used for?
  28. What do ‘class’ and ‘ID’ selectors pick when they are issued?
  29. How is clearfix css property useful?
  30. What is your least favorite part of working with CSS?
  31. What happens to text if 'auto' value is assigned to overflow property, to the element containing the text?
  32. Does overflow: hidden create a new block formatting context?
  33. How can you load css resources conditionally?
  34. How does inheritance work in CSS?

General

  1. Are HTML tags case sensitive?
  2. Explain Microdata in HTML5.
  3. What is the difference between the font size units em and rem?
  4. What is the sequence that follows when practical sheets arrive?
  5. What is the DOM? How does the DOM work?
  6. What is the difference between standards mode and quirks mode?
  7. How do absolute / relative / fixed / static positions work?
  8. What is progressive rendering?
  9. How is responsive design different from adaptive design?
  10. How would you optimize a website's assets/resources?
  11. What does CORS stand for and what issue does it address?
  12. How do I set the focus to first form on field?
  13. What is the main difference between Server sent events and Websockets?

CSS Advanced

  1. What is file splitting and why should you use it?
  2. How would you use media queries in a mobile-first approach?
  3. Explain the scenario you would use translate() instead of absolute positioning?
  4. What are the differences between visibility hidden and display none?


The Questions
HTML
1. What is semantic HTML?

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 tag is not used for bold statement as well as tag is used for italic. Instead of these we use and tags.

2. How to create a nested webpage in HTML?

The HTML iframe tag is used to display a nested webpage. In other words, it represents a webpage within a webpage. The HTML <iframe> tag defines an inline frame.

3. Why is a URL encoded in HTML?

An URL is encoded to convert non-ASCII characters into a format that can be used over the Internet because a URL is sent over the Internet by using the ASCII character-set only. If a URL contains characters outside the ASCII set, the URL has to be converted. The non-ASCII characters are replaced with a "%" followed by hexadecimal digits.

4. What is SVG?

HTML SVG is used to describe the two-dimensional vector and vector/raster graphics. SVG images and their behaviors are defined in XML text files. So as XML files, you can create and edit an SVG image with the text editor. It is mostly used for vector type diagrams like pie charts, 2-Dimensional graphs in an X, Y coordinate system.

5. What is the difference between progress and meter tag?

The progress tag is used to represent the progress of the task only while the meter tag is used to measure data within a given range.

6. Do all character entities display properly on all systems?

No, there are some character entities that cannot be displayed when the operating system that the browser is running on does not support the characters. When that happens, these characters are displayed as boxes.

7. What is the advantage of collapsing white space?

White spaces are a blank sequence of space characters, which is treated as a single space character in HTML. Because the browser collapses multiple spaces into a single space, you can indent lines of text without worrying about multiple spaces. This enables you to organize the HTML code into a much more readable format.

8. How do you create links to sections within the same page?

Links can be created using the <a> tag, with referencing through the use of the number (#) symbol. For example, you can have one line as <a href=”#topmost”>BACK TO TOP</a>, which would result in the words “BACK TO TOP” appearing on the webpage and links to a bookmark named topmost. You then create a separate tag command like <a name=”topmost”> somewhere on the top of the same webpage so that the user will be linked to that spot when he clicked on “BACK TO TOP”.

9. What is the use of alternative text in image mapping?

When you use image maps, it can easily become confusing and difficult to determine which hotspots correspond to which links. Using alternative text lets, you put a descriptive text on each hotspot link.

10. If the user’s operating system does not support the needed character, how can the symbol be represented?

In cases wherein their operating system does not support a particular character, it is still possible to display that character by showing it as an image instead.

11. Why are there both numerical and named character entity values?

The numerical values are taken from the ASCII values for the various characters, but these can be difficult to remember. Because of this, named character entity values were created to make it easier for web page designers to use.

12. What if there is no text between the tags or if a text was omitted by mistake? Will it affect the display of the HTML file?

If there is no text between the tags, then there is nothing to format. Therefore no formatting will appear. Some tags, especially tags without a closing tag like the <img> tag, do not require any text between them.

13. What are the limits of the text field size?

The default size for a text field is around 13 characters. However, if you include the size attribute, you can set the size value to be as low as 1. The maximum size value will be determined by the browser width. If the size attribute is set to 0, the size will be set to the default size of 13 characters.

14. How are active links different from normal links?

The default color for normal and active links is blue. Some browsers recognize an active link when the mouse cursor is placed over that link; others recognize active links when the link has the focus. Those that don’t have a mouse cursor over that link is considered a normal link.

15. What happens if you open the external CSS file in a browser?

When you try to open the external CSS file in a browser, the browser cannot open the file, because the file has a different extension. The only way to use an external CSS file is to reference it using tag within another HTML document.

16. Do you know which are two semantic tags are included in HTML5 version?

The <article> and <section> tags are two new tags that are included in HTML5. Articles can be composed of multiple sections that can have multiple articles. An article tag represents a full block of content which is a section of a bigger whole.

17. What is the Application Cache in HTML5 and why it is used?

The Application Cache concept means that a web application is cached. It can be accessible without the need for internet connection.

Some advantages of Application Cache:

  • Offline browsing – Web users can also use the application when they are offline.
  • Speed – Cached resources load quicker.
  • Reduce the server load – The web browser will only download updated resources from the server.
18. What are the tags used to separate a section of texts?

There are three tags that can be used to separate the texts: - <br> tag – Usually <br> tag is used to separate the line of text. It breaks the current line and conveys the flow to the next line - <p> tag – This contains the text in the form of a new paragraph. - <blockquote> tag – It is used to define a large quoted section. If you have a large quotation, then put the entire text within <blockquote>……….</blockquote> tag.

19. What is the difference between DIV and SPAN in HTML?

The difference between span and div is that a span element is in-line and usually used for a small chunk of HTML inside a line,such as inside a paragraph. Whereas, a div or division element is block-line which is equivalent to having a line-break before and after it and used to group larger chunks of code.

20. Is there any way to keep list elements straight in an HTML file?

By using indents, you can keep the list elements straight. If you indent each sub nested list in further than the parent list, you can easily determine the various lists and the elements that it contains.

21. Explain The Key Differences Between LocalStorage And SessionStorage Objects.

The key differences between localStorage and sessionStorage objects are as follows:

  • The localStorage object stores the data without an expiry date. However, sessionStorage object stores the data for only one session.
  • In the case of a localStorage object, data will not delete when the browser window closes. However, the data gets deleted if the browser window closes, in the case of sessionStorage objects.
  • The data in sessionStorage is accessible only in the current window of the browser. But, the data in the localStorage can be shared between multiple windows of the browser.
22. What is the relationship between the border and rule attributes?

Default cell borders, with a thickness of 1 pixel, are automatically added between cells if the border attribute is set to a nonzero value. Similarly, If the border attribute is not included, a default 1-pixel border appears when the rules attribute is added to the <table> tag.

23. What is difference between HTML and XHTML?

The differences between HTML and XHTML are:

  • HTML is an application of Standard Generalized Markup Language. Whereas, XML is an application of Extensible Markup Language.
  • The first one is a static Web Page whereas the later one is a dynamic Web Page.
  • HTML allows programmer to perform changes in the tags and use attribute minimization whereas XHTML when user need a new markup tag then user can define it in this.
  • HTML is about displaying information whereas XHTML is about describing the information.
24. What would happen if the HTML Document does not contain <!DOCTYPE>?

It instructs the Web Browser about the version of HTML used for creating the Web page. If the developer misses declaring the DOCTYPE information in the code, then new features and tags provided by HTML5, like <article>, <footer>, and <header> will not be supported. Additionally, the Browser may automatically go into Quirks or Strict Mode.

25. What are some of the key new features in HTML5?

Key new features of HTML5 include: - Improved support for embedding graphics, audio, and video content via the new <canvas>, <audio>, and <video> tags. - Extensions to the JavaScript API such as geolocation and drag-and-drop as well for storage and caching. - Introduction of “web workers”. - Several new semantic tags were also added to complement the structural logic of modern web applications. These include the <main>, <nav>, <article>, <section>, <header>, <footer>, and <aside> tags. - New form controls, such as <calendar>, <date>, <time>, <email>, <url>, and <search>.

26. What are “web workers”?

Web workers at long last bring multi-threading to JavaScript. A web worker is a script that runs in the background (i.e., in another thread) without the page needing to wait for it to complete. The user can continue to interact with the page while the web worker runs in the background. Workers utilize thread-like message passing to achieve parallelism.

27. What is the Geolocation API in HTML5?

HTML5’s Geolocation API lets users share their physical location with chosen web sites. JavaScript can capture a user’s latitude and longitude and can send it to the back-end web server to enable location-aware features like finding local businesses or showing their location on a map. Today, most browsers and mobile devices support the Geolocation API. The Geolocation API works with a new property of the global navigator object. The geolocation object is a service object that allows widgets to retrieve information about the geographic location of the user’s device.

28. What’s one main result if you do not specify a doctype in an HTML page?

New HTML5-specific tags will not be interpreted by the browser.

29. What’s the difference between ‘block’ and ‘inline’ elements?

Block elements are programmed so that they would take up as much space as possible. As opposed to that, inline elements are designed to take up a very minimal amount of space.

30. How would you group form elements?

If you want to collect and transfer certain form HTML elements into a single group, the fieldset tag is considered to be the best one to use.

31. Should you collapse white spaces?

This might come off as one of the trick HTML interview questions, simply because of the wording. But don’t get fooled – collapsing white spaces is considered to be quite beneficial.

In HTML, white spaces are considered to be characters, too. That means that they take up space. If you collapse them, you might be able to improve the readability of your project.

32. What are applets?

Applets are the small program which can be embedded with the web pages to perform some specific functionality like computation, animation.

33. How we use JavaScript with HTML?

By using script tag we can use JavaScript with HTML.

34. What are the web sockets?

Web Sockets is a next-generation bidirectional communication technology for web applications which operates over a single socket and is exposed via a JavaScript interface in HTML 5 compliant browsers.

35. What do you mean by Box Model?

Every Element on a Page is a Rectangular Box and may have Width, Height, Padding, Borders, and Margins. Every section of the box model relates to a CSS property: width, height, padding, border, and margin.

36. What is the meaning of markup in HTML?

The sequence of characters or other symbols which we usually use to insert at certain places in a word or text file in order to indicate how the file should look when it is displayed or printed or Basically to describe documents logical structure. The markup indicators are often known as tags. Elements and tags are two different words which we need to understand as there is a lot of confusion among public related to this fact. It must be noted that HTML documents contain tags, but do not contain the elements. It is a wide misconception that usually occurs in mind that both exist in HTML documents.elements are usually only generated after parsing step from these tags

37. How Do I Specify A Specific Combination Of Frames Instead Of The Default Document?

This is unfortunately not possible. When you navigate through a site using frames, the URL will not change as the documents in the individual frames change. This means that there is no way to indicate the combination of documents that make up the current state of the frameset.

The author can provide multiple frameset documents, one for each combination of frame content. These frameset documents can be generated automatically, perhaps being created on the fly by a CGI program. Rather than linking to individual content documents, the author can link to these separate frameset documents using TARGET="_top". Thus, the URL of the current frameset document will always specify the combination of frames being displayed, which allows links, bookmarks, etc. to function normally.

38. Why Aren't My Frames The Exact Size I Specified?

Older versions of Netscape Navigator seems to convert pixel-based frame dimensions to whole percentages, and to use those percentage-based dimensions when laying out the frames. Thus, frames with pixel-based dimensions will be rendered with a slightly different size than that specified in the frameset document. The rounding error will vary depending on the exact size of the browser window. Furthermore, Navigator seems to store the percentage-based dimensions internally, rather than the original pixel-based dimensions. Thus, when a window is resized, the frames are redrawn based on the new window size and the old percentage-based dimensions.

There is no way to prevent this behavior. To accommodate it, you should design your site to adapt to variations in the frame dimensions. This is another situation where it is a good idea to accommodate variations in the browser's presentation.

39. Is It Possible To Make The Html Source Not Viewable?

In short, there is no real method or script for making standard HTML source code not viewable. You may consider doing any of the below if they are concerned about your source code.

  • Create the web page in Macromedia Flash or a similar program. The visitor would need to download the Macromedia Flash plug-in and would be unable to view the source code for the flash applet.
  • There are various scripts that will disable the right click feature, preventing the user from saving images or viewing the source. However, this will not protect the source code of your page. For example, Internet Explorer users may still click "View" and "Source" to view the source code of the page, or a user could disable scripts and images can be saved by simply saving the web page to the hard drive.
  • There are several programs that will help scramble your code, making it difficult (not impossible) to read. Again, this is not going to prevent someone from viewing your code.
40. Explain Vbscript

This is a scripting language developed by Microsoft and is based loosely on Visual Basic. Its functionality in a web environment is dependant upon either an ASP engine or the Windows Scripting Host, and must be used on a Windows hosting platform.

41. How do I make a form so it can be submitted by the hitting ENTER?

The short answer is that the form that should just have one <INPUT TYPE=TEXT> and no TEXTAREA, though it can behave another form of elements like checkboxes and radio buttons.

42. What is shadow DOM?

encapsulate part of a DOM. hide subtree. you can have same ID in different shadow DOM. Polymers uses it. This way your DOM becomes reusable. if interviewer is not happy with your answer give him the links and tell him to spend a weekend on reading.

Advanced HTML
1. How is data stored in HTML5?

There are two ways to store data in HTML5 – with local storage and with session storage. Data that is stored in the local storage is safe and will not be eliminated after the developer decides to exit the browser. In session storage, once you exit the browser, the data is automatically deleted.

2. A portion of a text seems to climb out of the page boundaries. Why is that?

Normally, this situation is almost impossible – HTML has clearly defined boundaries that are set so that texts or images couldn’t pass them. However, on a rare occasion, a text might climb out of those boundaries. This is usually the case when the text was typed in a table that has some wrong set parameters (especially in width).

jQuery
1. What are the advantage of using jQuery?
  • Easy to use and learn.
  • Easily expandable.
  • Cross-browser support (IE 6.0+, FF 1.5+, Safari 2.0+, Opera 9.0+)
  • Easy to use for DOM manipulation and traversal.
  • Large pool of built in methods.
  • AJAX Capabilities.
  • Methods for changing or applying CSS, creating animations.
  • Event detection and handling.
  • Tons of plug-ins for all kind of needs.
2. Difference between ID selector and class selector in jQuery?

If you have used CSS, then you might know the difference between ID and class selector, It’s same with jQuery. ID selector uses ID e.g. #element1 to select element, while class selector uses CSS class to select elements. When you just need to select only one element, use ID selector, while if you want to select a group of element, having same CSS class than use class selector. There is good chance that, Interview will ask you to write code using ID and class selector. From syntax perspective, as you can see, another difference between ID and class selector is that former uses “#” and later uses “.” character. More detailed analysis and discussion, see answer.

3. What is main advantage of loading jQuery library using CDN?

Apart from many advantages including reducing server bandwidth and faster download, one of the most important is that, if browser has already downloaded same jQuery version from same CDN, than it won’t download it again. Since now days, almost many public websites use jQuery for user interaction and animation, there is very good chance that browser already have jQuery library downloaded. Curious reader, please see the answer for in depth analysis.

CSS
1. How do CSS precedence/cascading rules work? How does the !important directive affect the rules?

CSS style rules “cascade” in the sense that they follow an order of precedence. Global style rules apply first to HTML elements, and local style rules override them. For example, a style defined in a style element in a webpage overrides a style defined in an external style sheet. Similarly, an inline style that is defined in an HTML element in the page overrides any styles that are defined for that same element elsewhere.The !important rule is a way to make your CSS cascade but also have the rules you feel are most crucial always be applied. A rule that has the !important property will always be applied no matter where that rule appears in the CSS document. So if you wanted to make sure that a property always applied, you would add the !important property to the tag. So, to make the paragraph text always red, in the above example, you would write:p { color: #ff0000 !important; }p { color: #000000; }

2. How Do I Design For Backward Compatibility Using Style Sheets?

Existing HTML style methods (such as <font SIZE> and <b>) may be easily combined with style sheet specification methods. Browsers that do not understand style sheets will use the older HTML formatting methods, and style sheets specifications can control the appearance of these elements in browsers that support CSS1.

3. What Can Be Done With Style Sheets That Can Not Be Accomplished With Regular Html?

Many of the recent extensions to HTML have been tentative and somewhat crude attempts to control document layout. Style sheets go several steps beyond, and introduces complex border, margin and spacing control to most HTML elements. It also extends the capabilities introduced by most of the existing HTML browser extensions. Background colors or images can now be assigned to ANY HTML element instead of just the BODY element and borders can now be applied to any element instead of just to tables. For more information on the possible properties in CSS, see the Index DOT Css Property Index.

4. Why Shouldn't I Use Fixed Sized Fonts ?

Only in very rare situations we will find users that have a "calibrated" rendering device that shows fixed font sizes correct. This tells us that we can never know the real size of a font when it's rendered on the user end. Other people may find your choice of font size uncomfortable. A surprisingly large number of people have vision problems and require larger text than the average. Other people have good eyesight and prefer the advantage of more text on the screen that a smaller font size allows. What is comfortable to you on your system may be uncomfortable to someone else. Browsers have a default size for fonts. If a user finds this inappropriate, they can change it to something they prefer. You can never assume that your choice is better for them. So, leave the font size alone for the majority of your text. If you wish to change it in specific places (say smaller text for a copyright notice at the bottom of page), use relative units so that the size will stay in relationship to what the user may have selected already. Remember, if people find your text uncomfortable, they will not bother struggling with your web site. Very few (if any) web sites are important enough to the average user to justify fighting with the author's idea of what is best.

5. What are the benefits of CSS sprites?

If a web page has large no. of images that takes a longer time to load because each image separately sends out an HTTP request. The concept of CSS sprites is used to reduce the loading time for a web page because it combines the various small images into one image. It reduces the number of HTTP requests and hence the loading time.

CSS sprites combine multiple images into one image, limiting the number of HTTP requests a browser has to make, thus improving load times. Even under the new HTTP/2 protocol, this remains true.

Under HTTP/1.1, at most one request is allowed per TCP connection. With HTTP/1.1, modern browsers open multiple parallel connections (between 2 to 8) but it is limited. With HTTP/2, all requests between the browser and the server are multiplexed on a single TCP connection. This means the cost of opening and closing multiple connections is mitigated, resulting in a better usage of the TCP connection and limits the impact of latency between the client and server. It could then become possible to load tens of images in parallel on the same TCP connection.

However, according to benchmark results, although HTTP/2 offers 50% improvement over HTTP/1.1, in most cases the sprite set is still faster to load than individual images.

To utilize a spritesheet in CSS, one would use certain properties, such as background-image, background-position and background-size to ultimately alter the background of an element.

6. What is tweening?

It is the process of generating intermediate frames between two images. It gives the impression that the first image has smoothly evolved into the second one. It is an important method used in all types of animations. In CSS3, Transforms (matrix, translate, rotate, scale etc.) module can be used to achieve tweening.

7. What are the merits and demerits of embedded style sheets?

This is the basic CSS3 interview questions that have been frequently asked in an interview. Following is the merit and demerit are as follows:

Merits:

  • Multiple tag types can be created in a single document.
  • Styles, in a complex situation, can be applied by using the Selector and grouping methods.
  • Extra download in unnecessary.

Demerits:

  • Multiple documents cannot be controlled.
8. What does CSS selector mean?

A string equivalent of HTML elements by which declarations or a set of it, is declared and is a link that can be referred for linking HTML and Style sheet is CSS selector.

9. What is contextual selector?

Selector used to select special occurrences of an element is called contextual selector. A space separates the individual selectors. Only the last element of the pattern is addressed in this kind of selector. For e.g.: TD P TEXT {color: blue}

10. What is graceful degradation?

In case the component fails, it will continue to work properly in the presence of a graceful degradation. The latest browser application is used when a webpage is designed. As it is not available to everyone, there is a basic functionality, which enables its use to a wider audience. In case the image is unavailable for viewing, text is shown with the alt tag.

11. What is progressive enhancement?

It’s an alternative to graceful degradation, which concentrates on the matter of the web. The functionality is same, but it provides an extra edge to users having the latest bandwidth. It has been into prominent use recently with mobile internet connections expanding their base.

12. What is Alternate Style Sheet?

Alternate Style Sheets allows the user to select the style in which the page is displayed using the view>page style menu. Through Alternate Style Sheet, user can see a multiple version of the page on their needs and preferences.

13. How can CSS be cascaded to mix with user’s personal sheet?

Properties can be a set in recommended places and the document modified for CSS to mix with user’s personal sheet.

14. How does the Z index function?

Overlapping may occur while using CSS for positioning HTML elements. Z index helps in specifying the overlapping element. It is a number which can be positive or negative, the default value being zero.

15. What is CSS specificity?

CSS specificity is a score or rank that decides which style declaration has to be used to an element. (*) this universal selector has low specificity while ID selectors have high specificity.

16. Why background and color are the separate properties if they should always be set together?

There are two reasons behind this: - It enhances the legibility of style sheets. The background property is a complex property in CSS, and if it is combined with color, the complexity will further increase. - Color is an inherited property while the background is not. So this can make confusion further.

17. What is the use of ruleset?

The ruleset is used to identify that selectors can be attached with other selectors. It has two parts: - Selector - Selector indicates the HTML element you want to style. - Declaration Block - The declaration block can contain one or more declarations separated by a semicolon.

18. Do you use any CSS preprocessors, and which do you prefer?

If you’re working on a medium to large project, it’d be a good idea to use a CSS preprocessor. They allow you to write more concise CSS, split it up into multiple files and use a large number of very useful functions and mixins (you can even create your own!), along with variables.

The main players are Sass (also referred to as SCSS), LESS and Stylus, although arguably Sass is the biggest.

19. What are web safe fonts and fallback fonts?

Not all operating systems and browsers have the same fonts installed. Web safe fonts are fonts that are commonly pre-installed on many computer systems, such as Arial and Times New Roman. In case the browser or operating system doesn’t recognize the first font you set (e.g. Ubuntu), you should choose a web safe fallback font to display (e.g. Arial), followed by a generic font family (e.g. sans-serif). If your fallback font doesn’t display either, the browser can pick a generic font in the sans-serif family.

20. What are pseudo elements and what are they used for?

Pseudo elements are used to style particular parts of an element, rather than the whole thing. For example, you can use it to style the first line or first letter of a paragraph, text you’ve selected, or you can use it to insert text or shapes before or after an element.

They always start with a double colon - although a single colon is still allowed for backwards compatibility.

21. What are the disadvantages of using CSS?
  • Ascending by selectors is not possible
  • Limitations of vertical control
  • No expressions
  • No column declaration
  • Pseudo-class not controlled by dynamic behaviour
  • Rules, styles, targeting specific text not possible
22. Explain the CSS Box Model and its different elements.

The CSS box model describes the rectangular boxes that are generated for elements in the document tree and laid out according to the visual formatting model. Each box has a content area (e.g. text, an image, etc.) and an optional surrounding padding, border, and margin areas.

The CSS box model is responsible for calculating: - How much space a block element takes up. - Whether or not borders and/or margins overlap, or collapse. - A box’s dimensions.

23. What is the float property used for in CSS?

The float CSS property places an element on the left or right side of its container, allowing text and inline elements to wrap around it. The element is removed from the normal flow of the page, though it still remains a part of the flow (in contrast to absolute positioning).

24. Explain the difference in approach when designing a responsive website over a mobile-first strategy?

These two approaches are not exclusive. Making a website responsive means some elements will respond by adapting its size or other functionality according to the device’s screen size, typically the viewport width, through CSS media queries.

25. What are the advantages and disadvantages of using a CSS pre-processor??

The usage depends on the type of project but the following advantages/disadvantages come with a preprocessor.

Advantages:

  • CSS is made more maintainable.
  • Easy to write nested selectors.
  • Variables for consistent theming. Can share theme files across different projects.
  • Mixins to generate repeated CSS.
  • Sass features like loops, lists, and maps can make configuration easier and less verbose.
  • Splitting your code into multiple files. CSS files can be split up too but doing so will require an HTTP request to download each CSS file.

Disadvantages:

  • Requires tools for preprocessing. Re-compilation time can be slow.
  • Not writing currently and potentially usable CSS. For example, by using something like postcss-loader with webpack, you can write potentially future-compatible CSS, allowing you to use things like CSS variables instead of Sass variables. Thus, you’re learning new skills that could pay off if/when they become standardized.
26. How would you implement the basic layout components of the box model in CSS? Give an example.

Each element of the box model—border, content, margin, and padding—can be specified independently for each side of the element by listing dimensions in the following order: top, bottom, right, and left. Alternatively, multiple sides can be specified as a group by listing fewer parameters.

27. How do you define a pseudo class in CSS? What are they used for?

You can define a pseudo class by listing the selector followed by a colon and finally the pseudo class element. Pseudo classes can be used to give elements special states—the most common example being a:hover, which is used to change the color of a link when a mouse hovers over it. Other uses include using distinct styling for visited and unvisited links and styling an element differently when focused.

28. What do ‘class’ and ‘ID’ selectors pick when they are issued?

A class selector will pick an entire block of information, while the ID selector lets you pick a specific element that possesses a unique type of an ID number.

We went over classes and IDs a bit earlier on, but this is truly one of the more important CSS interview questions. Knowing the differences and varying features between classes, types, and IDs can be the turning point of any CSS-based job interview.

29. How is clearfix css property useful?

A clearfix is a way for an element to automatically clear its child elements, so that you don't need to add additional markup. It's generally used in float layouts where elements are floated to be stacked horizontally.

30. What is your least favorite part of working with CSS?

All people have things that they don’t like about their jobs. An honest answer to this question can help you place an applicant with the right team. For instance, if a person loves finding errors in CSS files, you may want to hire that applicant to work on a project with creative people who prefer focusing on the big picture.

What to look for in an answer:

  • Understanding the pros and cons of CSS.
  • Knowing what role the applicant could play.
  • Learning about the applicant's other interests.
31. What happens to text if 'auto' value is assigned to overflow property, to the element containing the text?

If text overflows, it is clipped and scroll bar appears.

32. Does overflow: hidden create a new block formatting context?

overflow property deals with the content if content size exceeds the allocated size for the content. You can make extra content visible, hidden, scroll or auto (viewport default behavior).

33. How can you load css resources conditionally?

@import allows you to load/ import stylesheet by using a path (uri) representing the location of the file. You can define one or more media by comma separation for which you want to load the stylesheet. If browser dont support the media stylesheet will not be loaded.

34. How does inheritance work in CSS?

Inheritance is a concept that is used in HTML and other languages but it is used in CSS as well to define the hierarchy of the element from top level to bottom level. In inheritance child will inherit the properties of parent. In this the restriction is being applied that not all the properties can be applied. Inheritance passes its properties to its children class so that the same property doesn’t have to define the same property. Inherited properties can be overrided by the children class if child uses the same name properties.

General
1. Are HTML tags case sensitive?

No!

2. Explain Microdata in HTML5.

Using Microdata, the metadata is nested within existing content on web pages. Search engines extract the microdata from a web page to provide a good browsing experience.

3. What is the difference between the font size units em and rem?

By default, the font size in a browser is 16px and can be increased or decreased in the browser settings. 1em equals the font-size given in the browser. Whereas, the rem value depends on root element that is HTML tag.

4. What is the sequence that follows when practical sheets arrive?

If a single selector has three different style definitions, the definition near the actual tag is the priority. Inline style takes priority over embedded style sheets, which gives priority to external style sheets.

5. What is the DOM? How does the DOM work?

The DOM (Document Object Model) is a cross-platform API that treats HTML documents as a tree structure consisting of nodes. These nodes (such as elements and text nodes) are objects that can be programmatically manipulated and any visible changes made to them are reflected live in the document. In a browser, this API is available to JavaScript where DOM nodes can be manipulated to change their styles, contents, placement in the document, or interacted with through event listeners.

  • The DOM was designed to be independent of any particular programming language, making the structural representation of the document available from a single, consistent API.
  • document.getElementById() and document.querySelector() are common functions for selecting DOM nodes.
  • Setting the innerHTML property to a new value runs the string through the HTML parser, offering an easy way to append dynamic HTML content to a node.
6. What is the difference between standards mode and quirks mode?

In Quirks mode, layout emulates nonstandard behavior in Navigator 4 and Internet Explorer 5. This is essential in order to support websites that were built before the widespread adoption of web standards. In Standards mode, the behavior is described by the HTML and CSS specifications.

For HTML documents, browsers use a <!DOCTYPE html> in the beginning of the document to decide whether to handle it in quirks mode or standards mode.

7. How do absolute / relative / fixed / static positions work?

absolute, place an element exactly where you want to place it. absolute position is actually set relative to the element's parent. if no parent available then relatively place to the page itself (it will default all the way back up to the element).

relative, means "relative to itself". Setting position: relative; on an element and no other positioning attributes, it will no effect on it's positioning. It allows the use of z-index on the element and it limits the scope of absolutely positioned child elements. Any child element will be absolutely positioned within that block.

fixed, element is positioned relative to viewport or the browser window itself. viewport doesn't changed if u scroll and hence fixed element will stay right in the same position.

static default for every single page element. The only reason you would ever set an element to position: static is to forcefully-remove some positioning that got applied to an element outside of your control.

sticky - Sticky positioning is a hybrid of relative and fixed positioning. The element is treated as relative positioned until it crosses a specified threshold, at which point it is treated as fixed positioned.

8. What is progressive rendering?

It is rendering the data as it’s being downloaded. This is particularly useful on documents that have tons of text. You can see it on a page that has a lot of text – and where the scrollbar will get shorter in length as more data comes in – increasing the vertical size of the document – yet, it would display the downloaded text immediately. As more data came down the pipe – the page would get longer. This didn’t rely on the closing body or html tag – and it certainly wouldn’t render the entire page on the server – then download – which is a standard complaint about modern frameworks. But there is a technique called “Flushing the Buffer” that can be implemented on the server.

9. How is responsive design different from adaptive design?

Both responsive and adaptive design attempt to optimize the user experience across different devices, adjusting for different viewport sizes, resolutions, usage contexts, control mechanisms, and so on.

Responsive design works on the principle of flexibility - a single fluid website that can look good on any device. Responsive websites use media queries, flexible grids, and responsive images to create a user experience that flexes and changes based on a multitude of factors. Like a single ball growing or shrinking to fit through several different hoops.

Adaptive design is more like the modern definition of progressive enhancement. Instead of one flexible design, adaptive design detects the device and other features and then provides the appropriate feature and layout based on a predefined set of viewport sizes and other characteristics. The site detects the type of device used and delivers the pre-set layout for that device. Instead of a single ball going through several different-sized hoops, you'd have several different balls to use depending on the hoop size.

10. How would you optimize a website's assets/resources?

Concatenate and compress CSS, JavaScript and HTML files wherever possible, configure your server to deliver a Gzip files, cache resources, set longer expirations dates on http headers of resources you don’t expect to change often – such as a logo. Images can be some of the heaviest files we deliver, so compress wisely. Soon the picture element will be implemented across browsers, so we can optimize the delivery of image content. Also in the near future consider using WebP format for images – it is quite smaller in size than JPEG and PNG files. Finally, use a CDN or other domains to host your resources and leverage domain sharding.

11. What does CORS stand for and what issue does it address?

Cross Origin Resource Sharing. To address the fact that browsers restrict cross-origin HTTP requests initiated from within scripts. CORS gives web servers cross-domain access controls, which enable secure cross-domain data transfers.

12. How do I set the focus to first form on field?

You cannot do this with of HTML. However, you can include an script after the form that sets of the focus to the appropriate field of like this:

<form id=”myform” name=”myform” action=…>

<input type=”text” id=”myinput” name=”myinput” …>

</form>

13. What is the main difference between Server sent events and Websockets?

The main difference is that Server sent events are one-way only from the server to the browser but Websockets establish a two-way communication.

CSS Advanced
1. What is file splitting and why should you use it?

File splitting helps organize your CSS into multiple files, decreasing page load time and making things easier to manage. If you’re working with any of the preprocessors above, you can start splitting up your files.

How you decide to split them up is up to you, but it can be useful to separate files by component. For example, you can have all your button styles in a file called _buttons.scss or all your header-specific styles in a file called _header.scss. Then, in your main file, say _app.scss, you can import those files by writing @import 'buttons';

This way you can also create separate stylesheets for separate areas of your website, where you might not need all styles. For example, if you have a web app, you probably don’t need to load all styles when people land on your homepage, when they haven’t even logged into your app yet. Simply create another file and import only those styles you need.

2. How would you use media queries in a mobile-first approach?

There’s no way to avoid these nowadays, everyone expects their website to work on mobile devices, even if they don’t specifically ask for it.

The most common approach is the mobile-first one. All styles outside of media queries are targeted at mobile devices. Then, through progressively larger media queries, you can style larger screens one step at a time.

3. Explain the scenario you would use translate() instead of absolute positioning?

Translate is a value of CSS transform. Changing transform or opacity does not trigger browser reflow or repaint but does trigger compositions; whereas changing the absolute positioning triggers reflow. Transform causes the browser to create a GPU layer for the element but changing absolute positioning properties uses the CPU. Hence translate() is more efficient and will result in shorter paint times for smoother animations. When using translate(), the element still occupies its original space (sort of like position: relative), unlike in changing the absolute positioning.

4. What are the differences between visibility hidden and display none?

display: none removes the element from the normal layout flow and allow other elements to fill in. visibility: hidden tag is rendered, it takes space in the normal flow but doesn't show it. display: none causes DOM reflow where is visibility: hidden doesn't.