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 esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM 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 id="app"></div>
@import 'https://fonts.googleapis.com/css?family=Noto+Sans'
// Font variables
$main-font: 'Noto Sans', sans-serif
// Color variables
$darkblue: rgba(40, 75, 99, 0.8)
$fadedwhite: rgba(255,255,255,.7)
$accentcolor: #58a4b0
$fbcolor: #3A5A98
$twcolor: #55ACEE
body
background: radial-gradient(ellipse farthest-corner at center top, #d8dbe2 0%, #a9bcd0 100%)
height: 100vh
font-family: $main-font
background: url('https://hd.unsplash.com/photo-1435777940218-be0b632d06db') no-repeat center center fixed
// App style
.Modal
position: absolute
top: 50%
left: 50%
transform: translate(-50%, -50%)
background: $darkblue
background-size: cover
border-radius: 5px
// Lost password style
& a
display: block
color: $fadedwhite
font-size: 12px
text-align: center
text-decoration: none
margin: 4px 0 10px 0
margin: 10px
&:hover
text-decoration: underline
// Input
.Input
display: flex
// Hack to be able to have a label pseudo element before the input field
flex-direction: row-reverse
align-items: center
border-bottom: 1px solid #58a4b0
margin: 0 20px
& input
border: 0
background: transparent
padding: 2px 10px
margin: 18px 4px 0 4px
color: $fadedwhite
font-family: $main-font
font-size: 14px
&:required
box-shadow: none
// Animation trigger for label::before
&:focus ~ label
opacity: 1
// label::before icons
&[type='text']
~ label
&::before
content: "\f007"
&[type='password']
~ label
&::before
content: "\f023"
// Label
label
font-family: FontAwesome
color: white
font-size: 14px
margin-top: 17px
transition: opacity .3s ease-in-out
// pseudo element before input field (see hack above)
&::before
padding: 5px 5px 0 0
opacity: 0.5
// Buttons
// Sign in button
form
& button
position: relative
margin: 15px 0 5px 0
left: 50%
transform: translateX(-50%)
background: $accentcolor
border: none
border-radius: 5px
padding: 10px
color: white
width: 85%
font-family: $main-font
font-size: 14px
cursor: pointer
// Social login buttons
.social-signin
text-align: center
& button
width: 40%
border: none
border-radius: 5px
cursor: pointer
padding: 10px
& i
font-size: 20px
color: white
&.fb
background: $fbcolor
margin-right: 13px
&.tw
background: $twcolor
// modal back button
.bringitback
position: absolute
left: 50%
top: 50%
transform: translateX(-50%)
background: $accentcolor
border: none
border-radius: 5px
padding: 10px
color: white
width: 200px
font-family: $main-font
font-size: 14px
cursor: pointer
// Fake logo
.logo
text-align: center
color: white
& i
display: block
padding: 20px 0 0 0
font-size: 70px
transform: translateX(-5px)
& span
color: $fadedwhite
text-transform: uppercase
// React CSS animations
// On enter
.animation-enter
opacity: .01
&.animation-enter-active
opacity: 1
transition: opacity .6s ease, margin .5s ease
// On leave
.animation-leave
margin-top: 0px
opacity: 1
&.animation-leave-active
margin-top: -30px
opacity: .01
transition: opacity .2s ease
// On mount
.animation-appear
opacity: 0.01
.animation-appear.animation-appear-active
opacity: 1
transition: opacity .5s ease-in
const ReactCSSTG = React.addons.CSSTransitionGroup;
// Main app
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
isVisible: true
}
// Bindings
this.handleSubmit = this.handleSubmit.bind(this);
this.handleRemount = this.handleRemount.bind(this);
}
handleSubmit(e) {
e.preventDefault();
this.setState({
isVisible: false
}, function() {
console.log(this.state.isVisible)
});
return false;
}
handleRemount(e) {
this.setState({
isVisible: true
}, function() {
console.log(this.state.isVisible)
});
e.preventDefault();
}
render() {
// const for React CSS transition declaration
let component = this.state.isVisible ? <Modal onSubmit={ this.handleSubmit } key='modal'/> : <ModalBack onClick={ this.handleRemount } key='bringitback'/>;
return <ReactCSSTG transitionName="animation" transitionAppear={true} transitionAppearTimeout={500} transitionEnterTimeout={500} transitionLeaveTimeout={300}>
{ component }
</ReactCSSTG>
}
}
// Modal
class Modal extends React.Component {
render() {
return <div className='Modal'>
<Logo />
<form onSubmit= { this.props.onSubmit }>
<Input type='text' name='username' placeholder='username' />
<Input type='password' name='password' placeholder='password' />
<button> Sign In</button>
</form>
<div className='social-signin'>
<button className="fb" onClick={ this.props.onClick }><i className="fa fa-facebook" aria-hidden="true"></i></button>
<button className="tw" onClick={ this.props.onClick }><i className="fa fa-twitter" aria-hidden="true"></i></button>
</div>
<a href='#'>Lost your password ?</a>
</div>
}
}
// Generic input field
class Input extends React.Component {
render() {
return <div className='Input'>
<input type={ this.props.type } name={ this.props.name } placeholder={ this.props.placeholder } required autocomplete='false'/>
<label for={ this.props.name } ></label>
</div>
}
}
// Fake logo
class Logo extends React.Component {
render() {
return <div className="logo">
<i className="fa fa-bug" aria-hidden="true"></i>
<span> awesome logo </span>
</div>
}
}
// Button to brind the modal back
class ModalBack extends React.Component {
render() {
return <button className="bringitback" onClick={ this.props.onClick } key={ this.props.className }>Brind the modal back !</button>
}
}
ReactDOM.render(<App />, document.getElementById('app'));
Also see: Tab Triggers