Pen Settings

HTML

CSS

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

JavaScript

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

Packages

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.

Behavior

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.

HTML

              
                <!-- Wrapping container for layout of all three different methods of components -->
<div class="articleList">

	<!-- Traditional html way -->
	<div class="articleCard1">
		<img class="articleCard1__image" src="https://picsum.photos/300/175" alt="Description of article thumbnail image" />
		<div class="articleCard1__textContent">
			<h3 class="articleCard1__title">
				Article Title
			</h3>
			<p class="articleCard1__summary">
				Brief summary of what this article is about. Lorem ipsum dolor sit amet blah blah blah yadda yadda.
			</p>
			<a class="articleCard1__link" href="#">
				Read full article
			</a>
		</div>
	</div>

	<!-- React way -->
	<div id="app"></div>

	<!-- Web components way -->
	<template id="article-card-template">
		<!-- When we insert this into a Shadow DOM, the styles will be scoped -->
		<style>
			@import "https://codepen.io/abottega/pen/5ca7425b385b9f87a2d43b73e328df56.css";
			/* The above line is needed to import the global styles to this web component, ideally you'd want to isolate your global styling to separate sections and only import the sections required by the component for better performance/loading */
			.container {
				max-width: 300px;
				display: inline-block;
			}
			.image {
				max-width: 100%;
				display: block;
				border-radius: var(--borderRadius) var(--borderRadius) 0 0;
			}
			.textContent {
				border: solid 1px #bdbdbd;
				border-top: 0;
				padding: var(--defaultSpacing);
				border-radius: 0 0 var(--borderRadius) var(--borderRadius);
			}
			.title {
				margin-bottom: var(--defaultSpacing);
			}
			.summary {
				margin-bottom: var(--defaultSpacing);
				line-height: 2.2rem;
			}
			.link {
				font-weight: bold;
				text-decoration: none;
				color: var(--brandPrimary);
				transition: border 200ms ease-in-out;
				border-bottom: solid 2px transparent;
				&:hover {
					border-bottom: solid 2px var(--brandPrimary);
				}
			}
		</style>
		<div class="container">
			<img class="image" src="https://picsum.photos/300/175" alt="Description of article thumbnail image" />
			<div class="textContent">
				<h3 class="title">
					Article Title
				</h3>
				<p class="summary">
					Brief summary of what this article is about. Lorem ipsum dolor sit amet blah blah blah yadda yadda.
				</p>
				<a class="link" href="#">
					Read full article
				</a>
			</div>
		</div>
	</template>

	<article-card></article-card>

</div>
              
            
!

CSS

              
                // Global styling first
@import url("https://fonts.googleapis.com/css2?family=Raleway:wght@100;400;500;600&display=swap");

// scss/sass variables
$defaultSpacing: 20px;
$borderRadius: 6px;
$brandPrimary: #0091ea;

// native css variables
:root {
	--defaultSpacing: 20px;
	--borderRadius: 6px;
	--brandPrimary: #0091ea;
}

/* set rem text size and styling */
html {
	font-size: 62.5%;
}

body {
	margin: $defaultSpacing; // scss/sass way of implementing variables
	margin: var(--defaultSpacing); // native css way of implementing variables
	font-family: "Raleway", sans-serif;
	font-size: 1.6rem;
}

h1,
h2,
h3,
h4,
h5,
h6,
p {
	margin: 0;
}

.articleList {
	display: flex;
	justify-content: center;
	> * {
		margin: 10px;
	}
}

// BEM + SCSS way
.articleCard1 {
	max-width: 300px;
	display: inline-block;
	&__image {
		max-width: 100%;
		display: block;
		border-radius: $borderRadius $borderRadius 0 0;
	}
	&__textContent {
		border: solid 1px #bdbdbd;
		border-top: 0;
		padding: $defaultSpacing;
		border-radius: 0 0 $borderRadius $borderRadius;
	}
	&__title {
		margin-bottom: $defaultSpacing;
	}
	&__summary {
		margin-bottom: $defaultSpacing;
		line-height: 2.2rem;
	}
	&__link {
		font-weight: bold;
		text-decoration: none;
		color: $brandPrimary;
		transition: border 200ms ease-in-out;
		border-bottom: solid 2px transparent;
		&:hover {
			border-bottom: solid 2px $brandPrimary;
		}
	}
}
              
            
!

JS

              
                // React way 

import React from "https://cdn.skypack.dev/react@17.0.1";
import ReactDOM from "https://cdn.skypack.dev/react-dom@17.0.1";
import styled, { ThemeProvider, createGlobalStyle } from "https://cdn.skypack.dev/styled-components@5.2.1";

const theme = {
	defaultSpacing: "20px",
	borderRadius: "6px",
	brandPrimary: "#0091ea"
};

const GlobalStyle = createGlobalStyle`
  	@import url("https://fonts.googleapis.com/css2?family=Raleway:wght@100;400;500;600&display=swap");
	/* set rem text size and styling */
	html {
		font-size: 62.5%;
	}
	body {
		margin: 20px;
		font-family: "Raleway", sans-serif;
		font-size: 1.6rem;
	}
	h1,
	h2,
	h3,
	h4,
	h5,
	h6,
	p {
		margin: 0;
	}
`

const Container = styled.div`
	max-width: 300px;
	display: inline-block;
`;
const Image = styled.img`
	max-width: 100%;
	display: block;
	border-radius: ${props => props.theme.borderRadius};
	border-bottom-left-radius: 0;
	border-bottom-right-radius: 0;
`;
const TextContent = styled.div`
	border: solid 1px #bdbdbd;
	border-top: 0;
	padding: ${props => props.theme.defaultSpacing};
	border-radius: ${props => props.theme.borderRadius};
	border-top-left-radius: 0;
	border-top-right-radius: 0;
`;
const Title = styled.h3`
	margin-bottom: ${props => props.theme.defaultSpacing};
`;
const Summary = styled.p`
	margin-bottom: ${props => props.theme.defaultSpacing};
	line-height: 2.2rem;
`;
const Link = styled.a`
	font-weight: bold;
	text-decoration: none;
	color: ${props => props.theme.brandPrimary};
	transition: border 200ms ease-in-out;
	border-bottom: solid 2px transparent;
	&:hover {
		border-color: ${props => props.theme.brandPrimary};
	}
`;

export default function ArticleCard2({
	imgSrc,
	imgAlt,
	title,
	summary,
	articleLink
}) {
	return (
		<Container>
			<Image src={imgSrc} alt={imgAlt} />
			<TextContent>
				<Title>{title}</Title>
				<Summary>{summary}</Summary>
				<Link href={articleLink}>Read full article</Link>
			</TextContent>
		</Container>
	);
}

const App = () => {
	return (
		<>
			<GlobalStyle />
			<ThemeProvider theme={theme}>
				<ArticleCard2
					imgSrc="https://picsum.photos/300/175"
					imgAlt="Description of article thumbnail image"
					title="Article Title"
					summary="Brief summary of what this article is about. Lorem ipsum dolor sit amet blah blah blah yadda yadda."
					articleLink="#"
				/>
			</ThemeProvider>
		</>
	);
};

ReactDOM.render(<App />, document.getElementById("app"));

// Web components way

class ArticleCard3 extends HTMLElement {
	constructor() {
		super();

		this.attachShadow({ mode: "open" }); // Creates a shadow DOM root node for the element

		const template = document.getElementById("article-card-template");
		const templateInstance = template.content.cloneNode(true); // Clones the contents of the template
		this.shadowRoot.appendChild(templateInstance); // Inserts the template contents into the shadow DOM
	}
}

customElements.define("article-card", ArticleCard3);

              
            
!
999px

Console