HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
Any URLs 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 its URL and the proper URL extension.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
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.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
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.
Using packages here is powered by Skypack, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ES6 import
usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<div class="appRoot"></div>
body {
position: relative;
color: #fff;
background-image: url(https://source.unsplash.com/II2ulqB-118/480x320);
background-repeat: no-repeat;
background-position: top center;
background-size: cover;
// Creating dark overlay for background image
&:after {
position: absolute;
top: 0;
left: 0;
z-index: 2;
content: "";
width: 100%;
height: 100vh;
background: rgba(0,0,0,.5);
}
}
@media screen and (min-width: 480px) {
body {
background-image: url(https://source.unsplash.com/II2ulqB-118/768x1080);
}
}
@media screen and (min-width: 768px) {
body {
background-image: url(https://source.unsplash.com/II2ulqB-118/992x1080);
}
}
@media screen and (min-width: 992px) {
body {
background-image: url(https://source.unsplash.com/II2ulqB-118/1400x1080);
}
}
// Avoid covering the text by overlay
body .container {
z-index: 3;
}
body:not(.page-gallery) .container {
position: absolute;
left: 0;
top: 50%;
right: 0;
transform: translateY(-50%);
}
body:not(.page-gallery) .appRoot {
position: relative;
min-height: 320px;
height: 100vh;
}
h1 {
margin-top: 32px;
margin-bottom: 32px;
text-align: center;
text-transform: uppercase;
}
img {
max-width: 100%;
}
.nav {
position: relative;
z-index: 99;
}
.nav-link {
font-weight: 700;
color: #eee;
transition: color .25s ease-out;
&:focus,
&:hover {
color: #aaa;
}
}
.nav-link-active,
.nav-link-active:focus {
color: #fff;
border-bottom: 2px solid;
}
// Add space above and below mobile nav
@media screen and (max-width: 768px) {
.navbar-collapse {
margin-top: 40px;
}
.navbar + div {
margin-top: 40px;
}
}
.page-gallery .col-4 {
padding-top: 15px;
padding-bottom: 15px;
}
.page-gallery img {
box-shadow: 0 15px 35px rgba(50,50,93,.1),0 5px 15px rgba(0,0,0,.07);
transition: box-shadow .25s ease-out;
&:hover {
box-shadow: 0 21px 35px rgba(50,50,93,.1),0 15px 15px rgba(0,0,0,.07);
}
}
// // Store all components of React Router inside variable
const {
Route,
Router,
Link,
hashHistory,
IndexRoute,
IndexLink
} = ReactRouter;
// Store the container for rendering our website
const appRoot = document.querySelector('.appRoot');
// Component for main component
class App extends React.Component {
render() {
return (
<div>
<Navigation />
{/* Render active Route or indexRoute */}
{this.props.children}
</div>
);
}
}
// Component for Home page
class Home extends React.Component {
componentWillMount() {
document.body.classList.add('page-home');
}
componentWillUnmount() {
document.body.classList.remove('page-home');
}
render() {
return (
<div className='container'>
<div className='row'>
<div className='col-md-10 push-md-1 col-lg-8 push-lg-2 text-center'>
<h1>Anthony Sabia</h1>
<p>A web designer & developer from New York, USA, who focuses on building interactive experiences & mobile apps, currently leading a design team at Spotify.</p>
</div>
</div>
</div>
);
}
}
// Component for About page
class About extends React.Component {
componentWillMount() {
document.body.classList.add('page-about');
}
componentWillUnmount() {
document.body.classList.remove('page-about');
}
render() {
return (
<div className='container'>
<div className='row'>
<div className='col-md-10 push-md-1 col-lg-8 push-lg-2'>
<h1>About Me</h1>
<p>I like to focus on creating unique and clean design concepts, prototypes and interactive experiences. My expertise and skills cover the whole design process, from research and to visual design and execution.</p>
<p>I work with a wide range of clients, from startups to well-established companies. My clients are usually looking for user-centered design and product design visions to help them improve their product and grow their brand.</p>
</div>
</div>
</div>
);
}
}
// Component for Contact page
class Contact extends React.Component {
componentWillMount() {
document.body.classList.add('page-contact');
}
componentWillUnmount() {
document.body.classList.remove('page-contact');
}
render() {
return (
<div className='container'>
<div className='row'>
<div className='col-md-8 push-md-2 col-lg-6 push-lg-3'>
<h1>Let's get in touch!</h1>
<form formAction='' className='card-form'>
<div className='row form-group'>
<div className='col-6'>
<input className='form-control' name='formName' id='formName' type='text' placeholder='Your name' />
</div>
<div className='col-6'>
<input className='form-control' name='formEmail' id='formEmail' type='email' placeholder='Your email address' />
</div>
</div>
<fieldset className='form-group'>
<textarea className='form-control' name='formMessage' id='formMessage' placeholder='Your message' required ></textarea>
</fieldset>
<fieldset className='form-group text-center'>
<button className='btn btn-primary' type='submit'>Send message</button>
</fieldset>
</form>
</div>
</div>
</div>
);
}
}
// Component for Gallery page
class Gallery extends React.Component {
componentWillMount() {
document.body.classList.add('page-gallery');
}
componentWillUnmount() {
document.body.classList.remove('page-gallery');
}
render() {
return (
<div className='container'>
<h1>Featured Projects</h1>
<p className='mb-4 text-center'>Selection of projects finished between years 2014 — 2016.</p>
<div className='row'>
<div className='col-4'>
<img src='https://d13yacurqjgara.cloudfront.net/users/40433/screenshots/3205585/dri.png' alt='' />
</div>
<div className='col-4'>
<img src='https://d13yacurqjgara.cloudfront.net/users/40433/screenshots/3213974/untitled-1.png' alt='' />
</div>
<div className='col-4'>
<img src='https://d13yacurqjgara.cloudfront.net/users/182336/screenshots/3219163/dribbble_shot.png' alt='' />
</div>
</div>
<div className='row'>
<div className='col-4'>
<img src='https://d13yacurqjgara.cloudfront.net/users/692322/screenshots/3217252/profile.png' alt='' />
</div>
<div className='col-4'>
<img src='https://d13yacurqjgara.cloudfront.net/users/13307/screenshots/3208495/web_site_tea.png' alt='' />
</div>
<div className='col-4'>
<img src='https://d13yacurqjgara.cloudfront.net/users/784847/screenshots/3218599/roposo.com_website_exploration.png' alt='' />
</div>
</div>
<div className='row'>
<div className='col-4'>
<img src='https://d13yacurqjgara.cloudfront.net/users/66340/screenshots/3206003/home.jpg' alt='' />
</div>
<div className='col-4'>
<img src='https://d13yacurqjgara.cloudfront.net/users/273461/screenshots/3218915/chewy.png' alt='' />
</div>
<div className='col-4'>
<img src='https://d13yacurqjgara.cloudfront.net/users/274994/screenshots/3218870/dashboard.png' alt='' />
</div>
</div>
</div>
);
}
}
// Component for NotFound - 404 - page
class NotFound extends React.Component {
componentWillMount() {
document.body.classList.add('page-not-found');
}
componentWillUnmount() {
document.body.classList.remove('page-not-found');
}
render() {
return (
<div className='container'>
<div className='row'>
<div className='col-md-10 push-md-1 col-lg-8 push-lg-2 text-center'>
<h1 className='mt-4 mb-4'>404!</h1>
<h2>The page you are looking for doesn't exist.</h2>
</div>
</div>
</div>
);
}
}
// Component for Navigation
class Navigation extends React.Component {
render() {
return (
<nav className='navbar navbar-toggleable-sm'>
<button className='navbar-toggler navbar-toggler-right' type='button' data-toggle='collapse' data-target='#navbarNav' aria-controls='navbarNav' aria-expanded='false' aria-label='Toggle navigation'>
<span className='navbar-toggler-icon'></span>
</button>
<div className='collapse navbar-collapse justify-content-center' id='navbarNav'>
<ul className='nav flex-column flex-md-row' role='nav'>
<li className='nav-item'>
{/* Note about Links: parent route is active when any child route is active (it has always class ¨'nav-link-active'). We want the link to '/' be active only when the index route is active. For this reason, we will use 'IndexLink' */}
<IndexLink to='/' className='nav-link' activeClassName='nav-link-active'>Home</IndexLink>
{/* 'activeClassName' allow us to add class when the link is active (current Route). Another option is using 'activeStyle' and CSS styles. */}
</li>
<li className='nav-item'>
{/* Link is similar to <a/> tag. The difference is that Link is aware of the Router (screen) it is rendered in. It allows you to wire together links with Routes (via 'to' attribute). */}
<Link className='nav-link' activeClassName='nav-link-active' to='/about'>About</Link>
</li>
<li className='nav-item'>
<Link className='nav-link' activeClassName='nav-link-active' to='/gallery'>Gallery</Link>
</li>
<li className='nav-item'>
<Link className='nav-link' activeClassName='nav-link-active' to='/contact'>Contact</Link>
</li>
</ul>
</div>
</nav>
);
}
}
ReactDOM.render((
<Router history={hashHistory}>
{/* 'hashHistory' manages the routing history with the hash portion of the URL. */}
<Route path='/' component={App}>
{/* IndexRoute allows us to render a component when we visit '/'.
Note: IndexRoute has no path - it becomes this.props.children of the parent when no other child of the parent matches. */}
<IndexRoute component={Home} />
{/* Each Route is child of 'App'. This allows the components inside of App share the navigation. Otherwise, we would need to add Navigation compoonent into every page (component) */}
<Route path='/about' component={About} />
<Route path='/gallery' component={Gallery} />
<Route path='/contact' component={Contact} />
<Route path='*' component={NotFound} />
</Route>
</Router>
), appRoot);
Also see: Tab Triggers