Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

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.

+ 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.


Auto Save

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.


                <div id="root"></div>


                body {
  font-family: sans-serif;
  font-size: 20px; /* the new 16px */

.tooltip-trigger-text {
  border-bottom: 1px dashed grey;

.tooltip-body {
  position: fixed;
  padding: 8px;
  background: #333;
  color: white;
  box-shadow: 2px 2px 3px rgba(0 ,0, 0, 0.3);
  text-align: center;
  font-size: 16px;


                class MyPortal extends React.PureComponent {
  constructor(props) {
    this.el = document.createElement('div');

  componentDidMount() {

  componentWillUnmount() {
  render() {
    return ReactDOM.createPortal(this.props.children, this.el);

class Tooltip extends React.PureComponent {
  constructor(props) {
    this.state = {
      visible: false,
    this.width = props.width || 256; = || 16;
    this.showTooltip = this.showTooltip.bind(this);
    this.hideTooltip = this.hideTooltip.bind(this);
  showTooltip() {
    // some maths to align the tooltip with whatever you just hovered over (the 'target')
    // or maybe it's 'math' in your weird country
    const style = { width: this.width }; // this style object will be passed as the tooltip's 'style' prop
    const dimensions = this.el.getBoundingClientRect(); // where on the screen is the target
    // center align the tooltip by taking both the target and tooltip widths into account
    style.left = (dimensions.left + (dimensions.width / 2)) - (this.width / 2);
    style.left = Math.max(, style.left); // make sure it doesn't poke off the left side of the page
    style.left = Math.min(style.left, document.body.clientWidth - this.width -; // or off the right
    if ( < window.innerHeight / 2) { // the top half of the page
      // when on the top half of the page, position the top of the tooltip just below the target (it will stretch downwards) = + dimensions.height +;
    } else {
      // when on the bottom half, set the bottom of the tooltip just above the top of the target (it will stretch upwards)
      style.bottom = (window.innerHeight - +;
      visible: true,
  hideTooltip() {
    this.setState({visible: false});
  render() {
    return (
      <span // a span so it's valid HTML no matter where it's used
        ref={el => this.el = el}
        {this.state.visible && (
            <div // this <div> isn't actually a child of the <span> above. Magic portal.

const App = () => (
      Some text, some of which <Tooltip text="This is some more info about that first thing that you should find every interesting.">requires explanation.</Tooltip> (Scroll down for more.)
    <div style={{ lineHeight: 80 }}>Scroll down</div>
      <Tooltip text="You hovered over the second one!">Something else to hover over</Tooltip> is what this is.
    <div style={{ lineHeight: 80 }}>Just more paddin'</div>

ReactDOM.render(<App/>, document.getElementById('root'));