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.
.container
.phone
.camera
.camera_lens
.mark
.speaker
.screen
.topbar
i.fa.fa-wifi
span 11:41
#calculator.calculator
.lock
.volume
body
color: white
font-family: 'Roboto'
.container
margin: 2% auto
width: 235px
.phone
background: #221e1f
border: 5px solid #4b473f;
height: 500px
width: 235px
border-radius: 30px
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24)
transition: all 0.3s linear
&:hover
box-shadow: 0 14px 28px rgba(0, 0, 0, 0.25), 0 10px 10px rgba(0, 0, 0, 0.22)
.camera
position: absolute
background: #585858
height: 10px
width: 10px
border-radius: 10px
margin-top: 17px
margin-left: 25px
.camera_lens
position: absolute
background-color: #0d0d0d
height: 5px
width: 5px
border-radius: 5px
margin-top: 20px
margin-left: 28px
.speaker
position: absolute
background-color: #574b4d
height: 5px
width: 50px
border-radius: 3px
margin-top: 17px
margin-left: 93px
.mark
position: absolute
background-color: #000
height: 8px
width: 20px
border-radius: 10px
margin-left: 108px
margin-top: 35px
.screen
background: #fff
position: absolute
height: 390px
width: 225px
margin-left: 0px
margin-top: 50px
background-size: 260px 450px
.topbar
font-size: 12px
color: #fff
text-align: right
background-color: #00BCD4
i
font-size: 12px
margin-right: 8px
vertical-align: middle
width: 10px
span
margin-right: 5px
margin-bottom: 2px
font-size: 10px
.lock
background-color: #797471
position: absolute
height: 35px
width: 3px
margin-left: 230px
margin-top: 100px
border-top-right-radius: 3px 3px
border-bottom-right-radius: 3px 3px
.volume
background-color: #797471
position: absolute
height: 75px
width: 3px
margin-top: 180px
margin-left: 230px
border-top-right-radius: 3px 3px
border-bottom-right-radius: 3px 3px
.display
height: 140px
overflow: hidden
.input
max-width:100%
box-sizing:border-box
border:none
text-align:right
outline:none
color:#5e5e5e
margin-top:5px
padding:12px
padding-bottom: 0
font-size:40px
overflow:hidden
.output
text-align:right
color: #7f7f7f
padding:12px
padding-top: 0
font-size:28px
font-weight:300
overflow:hidden
.keypad
background: #434343
color:white
float: left
padding: 10px 0
.key
border: none
background: #434343
font-size: 24px
font-weight: 300
width: 55px
height: 55px
&:hover, &:active, &:focus
background: #535353
.operators
background: #636363
color: white
float: left
padding: 5px 0
.key
background: #636363
font-size: 16px
height: 46px
width: 46px
min-width: 44px
display block
&:hover
background: #535353
.extendedOperators
background:#1de9b6
height: 240px
width: 14px
float: left
class Calculator extends React.Component {
constructor() {
super();
this.enterDigit = this.enterDigit.bind(this);
this.enterOperator = this.enterOperator.bind(this);
this.state = {
input: '',
output: '',
operator: null,
deleteToggle: 'DEL'
}
}
enterDigit(value) {
if(value === '=') {
this.setState({
input: this.state.output,
output: '',
operator: null,
deleteToggle: 'CLR'
})
} else if (this.state.operator !== null) {
var newInput = this.state.input + value;
var replace = newInput.replace(/x/g, '*').replace(/÷/g, '/');
var result = eval(replace);
this.setState({
input: newInput,
output: result,
deleteToggle: 'DEL'
})
} else {
this.setState({
input: this.state.input + value,
deleteToggle: 'DEL'
})
}
}
enterOperator(value) {
if(value == 'CLR') {
this.setState({
input: '',
output: '',
operator: null
})
} else if(value == 'DEL') {
this.setState({
input: this.state.input.slice(0, -1)
})
} else {
this.setState({
input: this.state.input + value,
operator: value.replace(/x/g, '*').replace(/÷/g, '/')
})
}
}
render() {
return(
<div>
<Display input={this.state.input} output={this.state.output} />
<CalcInput enterDigit={this.enterDigit} enterOperator={this.enterOperator} deleteToggle={this.state.deleteToggle} />
</div>
)
}
}
class Display extends React.Component {
constructor(props) {
super(props);
}
render() {
return(
<div className="display z-depth-3">
<div className="input">{this.props.input.toString()}</div>
<div className="output">{this.props.output}</div>
</div>
)
}
}
class CalcInput extends React.Component {
render(props) {
return(
<div>
<KeyPad className="keypad" enterDigit={this.props.enterDigit} />
<Operators enterOperator={this.props.enterOperator} deleteToggle={this.props.deleteToggle} />
<ExtendedOperators enterDigit={this.props.enterDigit} />
</div>
)
}
}
class KeyPad extends React.Component {
constructor(props) {
super(props);
}
mapKeys(arr) {
return arr.map(a => <Key key={a.toString()} value={a} enterValue={this.props.enterDigit} />);
}
render() {
let rowOne = [7, 8, 9],
rowTwo = [4, 5, 6],
rowThree = [1, 2, 3],
rowFour = [".", 0, '='];
return(
<div className="keypad">
<div className="keyRow">{this.mapKeys(rowOne)}</div>
<div className="keyRow">{this.mapKeys(rowTwo)}</div>
<div className="keyRow">{this.mapKeys(rowThree)}</div>
<div className="keyRow">{this.mapKeys(rowFour)}</div>
</div>
)
}
}
class Key extends React.Component {
render() {
const value = this.props.value;
return(
<button className="key waves-effect waves-circle waves-light" onClick={this.props.enterValue.bind(this, value)}>{value}</button>
)
}
}
class Operators extends React.Component {
constructor() {
super();
}
render() {
return(
<div className="operators">
<Key value={this.props.deleteToggle} enterValue={this.props.enterOperator} />
<Key value='÷' enterValue={this.props.enterOperator} />
<Key value='x' enterValue={this.props.enterOperator} />
<Key value='-' enterValue={this.props.enterOperator} />
<Key value='+' enterValue={this.props.enterOperator} />
</div>
)
}
}
class ExtendedOperators extends React.Component {
render() {
return(
<div className="extendedOperators"></div>
)
}
}
ReactDOM.render(<Calculator />, document.getElementById('calculator'));
Also see: Tab Triggers