Skip to content

Commit fe5ce8a

Browse files
committed
srcset attribute
1 parent e71f28b commit fe5ce8a

File tree

1 file changed

+61
-15
lines changed

1 file changed

+61
-15
lines changed

README.md

Lines changed: 61 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ There are five new form elements in the HTML5 forms specification: `<datalist>`,
186186
</datalist>
187187
```
188188

189-
[Live Example](https://learning-zone.github.io/html-interview-questions/html5-semantic-tags/datalist.html)
189+
[Live demo](https://learning-zone.github.io/html-interview-questions/html5-semantic-tags/datalist.html)
190190

191191
**2.) Meter Tag**: indicates a numeric value that falls within a range. The tag supports a number of attributes:
192192
value: If you don\'t specify a value, the first numeric value inside the `<meter></meter>` pair becomes the value.
@@ -205,7 +205,7 @@ value: If you don\'t specify a value, the first numeric value inside the `<meter
205205
<p>Pollution Level: <meter low="60" high="80" max="100" value="85">Very High</meter></p>
206206
```
207207

208-
[Live Example](https://learning-zone.github.io/html-interview-questions/html5-semantic-tags/meter.html)
208+
[Live demo](https://learning-zone.github.io/html-interview-questions/html5-semantic-tags/meter.html)
209209

210210
**3.) Output Tag**: is meant to display text output. It indicates a section of the page that can be modified by a script (usually JavaScript).
211211

@@ -217,7 +217,7 @@ value: If you don\'t specify a value, the first numeric value inside the `<meter
217217
</form>
218218
```
219219

220-
[Live Example](https://learning-zone.github.io/html-interview-questions/html5-semantic-tags/output.html)
220+
[Live demo](https://learning-zone.github.io/html-interview-questions/html5-semantic-tags/output.html)
221221

222222
**4.) Progress Tag**: indicates how much of a task has been completed (often marked as a percentage). It is expected to be modified through JavaScript code.
223223

@@ -244,7 +244,7 @@ value: If you don\'t specify a value, the first numeric value inside the `<meter
244244
</script>
245245
```
246246

247-
[Live Example](https://learning-zone.github.io/html-interview-questions/html5-semantic-tags/progress.html)
247+
[Live demo](https://learning-zone.github.io/html-interview-questions/html5-semantic-tags/progress.html)
248248

249249
<div align="right">
250250
<b><a href="#">↥ back to top</a></b>
@@ -643,7 +643,7 @@ Syntax:
643643
</html>
644644
```
645645

646-
[Live Example](https://learning-zone.github.io/html-interview-questions/assets/files/application-cache.html)
646+
[Live demo](https://learning-zone.github.io/html-interview-questions/assets/files/application-cache.html)
647647

648648
*Note: Using the application caching feature described here is at this point highly discouraged; it\'s in the process of being removed from the Web platform. Use **Service Workers** instead. In fact as of Firefox 44, when AppCache is used to provide offline support for a page a warning message is now displayed in the console advising developers to use Service workers instead (bug 1204581).*
649649

@@ -1211,7 +1211,7 @@ function toggleFullScreen() {
12111211
}
12121212
```
12131213

1214-
[Live Example](https://learning-zone.github.io/html-interview-questions/assets/files/html5-api.html)
1214+
[Live demo](https://learning-zone.github.io/html-interview-questions/assets/files/html5-api.html)
12151215

12161216
<div align="right">
12171217
<b><a href="#">↥ back to top</a></b>
@@ -1282,7 +1282,7 @@ if ("geolocation" in navigator) {
12821282
</html>
12831283
```
12841284

1285-
[Live Example](https://learning-zone.github.io/html-interview-questions/assets/files/geolocation.html)
1285+
[Live demo](https://learning-zone.github.io/html-interview-questions/assets/files/geolocation.html)
12861286

12871287
<div align="right">
12881288
<b><a href="#">↥ back to top</a></b>
@@ -1456,7 +1456,7 @@ socket.addEventListener('message', function(event) {
14561456
</html>
14571457
```
14581458

1459-
[Live Example](https://learning-zone.github.io/html-interview-questions/assets/files/canvas.html)
1459+
[Live demo](https://learning-zone.github.io/html-interview-questions/assets/files/canvas.html)
14601460

14611461
<div align="right">
14621462
<b><a href="#">↥ back to top</a></b>
@@ -1502,7 +1502,7 @@ There are following advantages of using SVG over other image formats like JPEG,
15021502
</html>
15031503
```
15041504

1505-
[Live Example](https://learning-zone.github.io/html-interview-questions/assets/files/svg.html)
1505+
[Live demo](https://learning-zone.github.io/html-interview-questions/assets/files/svg.html)
15061506

15071507
### **Canvas**
15081508

@@ -1528,7 +1528,7 @@ Canvas is a HTML element is used to draw graphics on a web page. It is a bitmap
15281528
</html>
15291529
```
15301530

1531-
[Live Example](https://learning-zone.github.io/html-interview-questions/assets/files/canvas.html)
1531+
[Live demo](https://learning-zone.github.io/html-interview-questions/assets/files/canvas.html)
15321532

15331533
**Differences between SVG and Canvas**
15341534

@@ -1588,7 +1588,7 @@ Example
15881588
</html>
15891589
```
15901590

1591-
[Live Example](https://learning-zone.github.io/html-interview-questions/assets/files/drag-drop.html)
1591+
[Live demo](https://learning-zone.github.io/html-interview-questions/assets/files/drag-drop.html)
15921592

15931593
<div align="right">
15941594
<b><a href="#">↥ back to top</a></b>
@@ -1814,7 +1814,7 @@ The `<iframe>` HTML element represents a nested browsing context, embedding anot
18141814
</html>
18151815
```
18161816

1817-
[Live Example](https://learning-zone.github.io/html-interview-questions/assets/files/iframe.html)
1817+
[Live demo](https://learning-zone.github.io/html-interview-questions/assets/files/iframe.html)
18181818

18191819
### **The Iframe Tag Attributes**
18201820

@@ -1855,7 +1855,7 @@ The `<mark>` HTML element represents text which is marked or highlighted for ref
18551855
</html>
18561856
```
18571857

1858-
[Live Example](https://learning-zone.github.io/html-interview-questions/assets/files/mark.html)
1858+
[Live demo](https://learning-zone.github.io/html-interview-questions/assets/files/mark.html)
18591859

18601860
<div align="right">
18611861
<b><a href="#">↥ back to top</a></b>
@@ -2105,7 +2105,7 @@ The `<small>` HTML element represents side-comments and small print, like copyri
21052105
</html>
21062106
```
21072107

2108-
[Live Example](https://learning-zone.github.io/html-interview-questions/assets/files/small-element.html)
2108+
[Live demo](https://learning-zone.github.io/html-interview-questions/assets/files/small-element.html)
21092109

21102110
<div align="right">
21112111
<b><a href="#">↥ back to top</a></b>
@@ -2279,7 +2279,53 @@ In addition, while HTML5 defines some rules to follow for an invalid HTML5 docum
22792279
<b><a href="#">↥ back to top</a></b>
22802280
</div>
22812281

2282-
#### Q. ***Why you would use a srcset attribute in an image tag? Explain the process the browser used when evaluating the content of this attribute.***
2282+
## Q. ***Why you would use a srcset attribute in an image tag? Explain the process the browser used when evaluating the content of this attribute.***
2283+
2284+
The `srcset` attribute allows to define a list of different image resources along with size information so that browser can pick the most appropriate image based on the actual device\'s resolution.
2285+
2286+
**Syntax**
2287+
2288+
```html
2289+
<img
2290+
srcset="
2291+
url size,
2292+
url size,
2293+
url size "
2294+
src="default url"
2295+
>
2296+
```
2297+
2298+
### **1. Using display density descriptor**
2299+
2300+
`srcset` provides a comma-separated list of image resources along with display density it should be used, for example1x, 2x etc.
2301+
2302+
**Example**
2303+
2304+
```html
2305+
<img src="image.jpg"
2306+
srcset="image.jpg,
2307+
image_2x.jpg 2x"
2308+
/>
2309+
```
2310+
2311+
### **2. Using width descriptor**
2312+
2313+
The syntax is similar to the display density descriptor, but instead of display density values, we provide the actual width of the image.
2314+
2315+
**Example**
2316+
2317+
```html
2318+
<img src="image.jpg"
2319+
srcset="small.jpg 300w,
2320+
medium.jpg 600w,
2321+
large.jpg 900w"
2322+
/>
2323+
```
2324+
2325+
<div align="right">
2326+
<b><a href="#">↥ back to top</a></b>
2327+
</div>
2328+
22832329
#### Q. ***What is an HTML preprocessor and are you using it?***
22842330
#### Q. ***What is WebP?***
22852331
#### Q. ***Could you generate a public key in HTML?***

0 commit comments

Comments
 (0)