Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource


Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource


Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.


Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.


		<h1>Responsive Images Demo</h1>

		<p>As part of making your websites more 'responsive friendly', there are a couple of proposals for responsive images that were developed by the <a href="" target="_blank">Responsive Images Community Group</a>. There is the &lt;picture&gt; element which allows for 'art direction' of an image by using multiple sources, as well as the "srcset" and "sizes" attributes which allow us to offer browsers a variety of image resolutions to choose from.</p>

		<p>It is a good idea to take a look at <a href="" target="_blank">how supported "srcset"</a> and <a href="" target="_blank">the &lt;picture&gt; element</a> are before use.</p>

		<section id="srcset">

			<h2>"srcset" Example</h2>

				The srcset attribute allows us to define a comma separated list of different files and widths at which they should be loaded. In this case we are telling the browser to pick the image that makes sense for the display size that it has been loaded for:

					'img/Puppies_cropped-400.jpg 400w' is providing the file, and the pixel width of the original image. In this case 400 pixels. We use the 'w' (width) descriptor to define the 'true width' of the image.

				The more complicated part of this is the sizes attribute, where we are helping the browser understand how the image may be 'scaled' at different sizes. This part breaks our separation of styling (CSS) and content (HTML) somewhat, but allows for much more efficient and appropriate selection of images by the browser when needed. In this case we provide a comma-separated list of media queries that define the size the image will be at in those different queries:

					'(min-width:75rem) 50vw' is stating that at 75rem and larger, this image will be 50% of the viewport width. This lines up with our main.css file which switches to a two column layout at 75rem.

					The '100vw' value at the end of the list is the 'default' for this image.

				The img element below has been broken onto separate lines for readability. It is not required that you do this.
			<div class="grid two-col">
					alt="A collection of Nova Scotia Duck-tolling Retriever puppies"
						" 400w, 1000w, 1600w"
						"(min-width: 75rem) 50vw,
					<!-- A blank column for the purposes of our tutorial -->


		<section id="picture">

			<h2>&lt;picture&gt; Example</h2>

				Because the picture element defines a number of sources to work with, we need to open and close the element (unlike our img element).

					Below the source element defines a series of images to load using the srcset attribute that we have seen before. In addition to this we use the media attribute - which behaves like our CSS media queries - to define a width at which the source attribute should be come active.
				<source srcset=" 1000w, 2000w, 3000w" media="(min-width: 60rem)">

					We can embed the img element, with srcset, AND original src attribute to allow for backwards compatibility. In this case the img element also acts as the 'default' if the media conditions in the source element above are not met.

					Also note that we are NOT defining the height and width of the img element below. This is on purpose because the source element above may end up loading a differently sized image, rendering the height and width attributes incorrect.
				<img src=""  alt="A collection of Nova Scotia Duck-tolling Retriever puppies" srcset=" 400w, 1000w, 1600w" sizes= "(min-width: 75rem) 50vw, 100vw">





                * {
	box-sizing: border-box;

body {
	margin: 0;
	padding: 1rem;
	font-family: Verdana, sans-serif;

p {
	max-width: 36rem;

section {
	margin-top: 6rem;

img {
	max-width: 100%;
	height: auto;

.grid {
	display: grid;

@media (min-width: 75rem) {

	.grid.two-col {
		grid-template-columns: 1fr 1fr;