cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

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. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

Quick-add: + add another resource

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.

Quick-add: + add another resource

Code Indentation


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.

              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;
    this.space = props.space || 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(this.space, 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 - this.space); // or off the right
    if (dimensions.top < 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)
      style.top = dimensions.top + dimensions.height + this.space;
    } 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 - dimensions.top) + this.space;
      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>
    <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'));

Loading ..................