Top Related Projects
A CSS only tooltip library for your lovely websites.
Tooltip, popover, dropdown, and menu library
A JavaScript library to position floating elements and create interactions for them.
💬 Minimal, accessible, ultra lightweight css tooltip library. Just 1kb.
Quick Overview
Balloon.css is a lightweight and simple CSS library for creating tooltips without relying on JavaScript. It provides an easy way to add tooltips to HTML elements using only CSS, making it a lightweight and efficient solution for adding informative pop-ups to web pages.
Pros
- Lightweight and dependency-free (pure CSS solution)
- Easy to implement with minimal markup changes
- Customizable appearance through CSS variables
- Supports various positioning options (top, bottom, left, right)
Cons
- Limited functionality compared to JavaScript-based tooltip libraries
- No built-in support for complex tooltip content (e.g., HTML)
- May not work well with dynamically generated content
- Lacks advanced features like animations or click-to-show tooltips
Code Examples
- Basic tooltip:
<button aria-label="This is a tooltip" data-balloon-pos="up">
Hover me
</button>
- Tooltip with custom length:
<button aria-label="This is a long tooltip that wraps" data-balloon-length="large" data-balloon-pos="up">
Hover for a long tooltip
</button>
- Tooltip with custom styles:
<button
aria-label="Custom styled tooltip"
data-balloon-pos="right"
style="--balloon-color: #ff0000; --balloon-font-size: 14px;"
>
Hover for custom style
</button>
Getting Started
- Include the Balloon.css file in your HTML:
<link rel="stylesheet" href="https://unpkg.com/balloon-css/balloon.min.css">
- Add tooltips to your HTML elements using the
aria-label
anddata-balloon-pos
attributes:
<button aria-label="This is a tooltip" data-balloon-pos="up">Hover me</button>
<span aria-label="Another tooltip" data-balloon-pos="right">Hover this text</span>
- Customize the appearance using CSS variables if needed:
:root {
--balloon-color: #1a1a1a;
--balloon-font-size: 12px;
--balloon-move: 4px;
}
That's it! Your tooltips should now be working with Balloon.css.
Competitor Comparisons
A CSS only tooltip library for your lovely websites.
Pros of hint.css
- More customization options and themes out of the box
- Supports more positioning variants (top, bottom, left, right, and corners)
- Includes SASS mixins for easier integration into existing projects
Cons of hint.css
- Larger file size due to more features and options
- Slightly more complex implementation for basic use cases
- Requires additional HTML attributes for some functionality
Code Comparison
hint.css:
<p class="hint--top" aria-label="This is a tooltip">Hover me</p>
balloon.css:
<button data-balloon="This is a tooltip" data-balloon-pos="up">Hover me</button>
Both libraries offer simple implementation, but hint.css uses CSS classes and aria attributes, while balloon.css uses data attributes for positioning and content.
Summary
hint.css provides more features and customization options, making it suitable for complex projects with diverse tooltip requirements. balloon.css offers a simpler, lightweight solution for basic tooltip needs. The choice between the two depends on the project's specific requirements and the desired level of customization.
Tooltip, popover, dropdown, and menu library
Pros of Tippyjs
- More feature-rich with extensive customization options
- Better browser compatibility, including IE11 support
- Larger community and more frequent updates
Cons of Tippyjs
- Larger file size due to more features
- Steeper learning curve for advanced usage
- Requires JavaScript, unlike Balloon.css's pure CSS approach
Code Comparison
Balloon.css (HTML):
<button aria-label="Tooltip content" data-balloon-pos="up">Hover me!</button>
Tippyjs (JavaScript):
tippy('#myButton', {
content: 'Tooltip content',
placement: 'top'
});
Both libraries aim to provide tooltip functionality, but they differ in their approach. Balloon.css offers a lightweight, CSS-only solution that's easy to implement but has limited customization. Tippyjs, on the other hand, provides a more robust JavaScript-based solution with extensive features and customization options.
Balloon.css is ideal for simple tooltip needs and projects where minimizing JavaScript usage is a priority. Tippyjs is better suited for complex applications requiring advanced tooltip functionality and extensive customization.
The choice between the two depends on the specific project requirements, performance considerations, and desired level of customization.
A JavaScript library to position floating elements and create interactions for them.
Pros of Floating UI
- More comprehensive positioning library with advanced features
- Supports multiple frameworks (React, Vue, etc.) and vanilla JS
- Actively maintained with frequent updates and improvements
Cons of Floating UI
- Steeper learning curve due to more complex API
- Requires JavaScript, unlike Balloon.css which is CSS-only
- Larger file size and potential performance impact for simple use cases
Code Comparison
Balloon.css (HTML):
<button aria-label="Tooltip content" data-balloon-pos="up">Hover me!</button>
Floating UI (JavaScript):
import {computePosition, flip, shift, offset} from '@floating-ui/dom';
computePosition(button, tooltip, {
placement: 'top',
middleware: [offset(6), flip(), shift({padding: 5})],
}).then(({x, y}) => {
Object.assign(tooltip.style, {
left: `${x}px`,
top: `${y}px`,
});
});
Summary
Balloon.css is a lightweight, CSS-only solution for simple tooltips, while Floating UI offers a more powerful and flexible positioning library for complex UI components. Balloon.css is easier to implement for basic use cases, but Floating UI provides greater control and adaptability for advanced scenarios across various frameworks.
💬 Minimal, accessible, ultra lightweight css tooltip library. Just 1kb.
Pros of Microtip
- Smaller file size (1.5KB vs 3.5KB for Balloon.css)
- No JavaScript required, pure CSS solution
- Supports more positioning options (12 vs 4 for Balloon.css)
Cons of Microtip
- Less customization options out of the box
- Fewer animation effects available
- Not as actively maintained (last update 2 years ago vs 5 months for Balloon.css)
Code Comparison
Microtip:
<button aria-label="Label" data-microtip-position="top" role="tooltip">
Hover me
</button>
Balloon.css:
<button aria-label="Label" data-balloon-pos="up">
Hover me
</button>
Both libraries use similar HTML attribute-based approaches for tooltip implementation. Microtip uses data-microtip-position
and role="tooltip"
, while Balloon.css uses data-balloon-pos
. The main difference is in the attribute names and the additional role
attribute in Microtip.
Overall, Microtip is lighter and offers more positioning options, while Balloon.css provides more customization and animation features. The choice between the two depends on specific project requirements and preferences for file size vs. feature set.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Balloon.css: Simple tooltips made of pure CSS.
Simple tooltips made of pure CSS
Balloon.css lets you add tooltips to elements without JavaScript and in just a few lines of CSS.
It weights ~1.1kb minified (Brotli).
Demo & Playground
You can play with Balloon.css here: https://jsfiddle.net/kuzmd942/
You also can check more examples at the website: https://kazzkiq.github.io/balloon.css/
Usage
Installation
Using npm:
npm install balloon-css
You can then import the CSS file directly into your JS (using Webpack, etc):
// Your index.js file, etc.
import 'balloon-css';
or import the source file if using SASS/SCSS:
/* Your main.scss file, etc. */
@import "~balloon-css/src/balloon"
CDN version:
If you don't want to use npm, there is a CDN option:
<!-- This link will always fetch the latest version of Balloon.css -->
<link rel="stylesheet" href="https://unpkg.com/balloon-css/balloon.min.css">
Manually:
Simply download balloon.min.css
from this repo and add it to your HTML. e.g.
<link rel="stylesheet" href="path/to/balloon.min.css">
Positioning
For positioning, use data-balloon-pos
attribute with one of the values: up
, down
, left
, right
, up-left
, up-right
, down-left
or down-right
:
<button aria-label="Whats up!" data-balloon-pos="up">Hover me!</button>
<button aria-label="Whats up!" data-balloon-pos="left">Hover me!</button>
<button aria-label="Whats up!" data-balloon-pos="right">Hover me!</button>
<button aria-label="Whats up!" data-balloon-pos="down">Hover me!</button>
<button aria-label="Whats up!" data-balloon-pos="up-left">Hover me!</button>
<button aria-label="Whats up!" data-balloon-pos="up-right">Hover me!</button>
<button aria-label="Whats up!" data-balloon-pos="down-left">Hover me!</button>
<button aria-label="Whats up!" data-balloon-pos="down-right">Hover me!</button>
Showing tooltips programatically
If you want to show tooltips even when user interaction isn't happening, you can simply use the data-balloon-visible
attribute:
<button aria-label="Whats up!" data-balloon-pos="up" id="show-tip">Hover me!</button>
<script>
const btn = document.getElementById('show-tip')
btn.setAttribute('data-balloon-visible', '')
</script>
Disabling animation
If for some reason you do not want animations in your tooltips, you can use the data-balloon-blunt
attribute for that.
<button data-balloon-blunt aria-label="No animation!" data-balloon-pos="up">No animation!</button>
Customizing Tooltips
Balloon.css exposes CSS variables to make it easier to customize tooltips:
--balloon-border-radius
--balloon-color
--balloon-font-size
--balloon-move
This way, you can use custom CSS to make your own tooltip styles:
/* Add this to your CSS */
.tooltip-red {
--balloon-color: red;
}
.tooltip-big-text {
--balloon-font-size: 20px;
}
.tooltip-slide {
--balloon-move: 30px;
}
If you want to customize tooltips globally, use the :root
selector:
/* All tooltips would now be square and blue */
:root {
--balloon-border-radius: 0;
--balloon-color: blue;
}
Glyphs and Icon Fonts
You can also add any HTML special character to your tooltips, or even use third-party Icon fonts:
<button aria-label="HTML special characters: ☻ ✂ ♜" data-balloon-pos="up">Hover me!</button>
<button aria-label="Emojis: ð ð¬ ð ð ð ð ð
ð" data-balloon-pos="up">Hover me!</button>
Example using Font Awesome:
<button class="fa" aria-label="Font Awesome:     " data-balloon-pos="up">Hover me!</button>
Contributing
Balloon.css is mantained in SASS and LESS. To contribute with bugfixes and enchancements you must follow this steps:
- Clone repo. E.g.
git clone https://github.com/kazzkiq/balloon.css.git
- Run
npm install
- Edit SASS file and run
npm run build
to generate the production CSS files. - Make sure to test the production files over the website (branch
gh-pages
) before submitting a Pull Request.
Note 1: Remember to update the SASS file instead of the generated ones (balloon.css
and balloon.min.css
are generated on every build from SASS file).
Credits
Made by Claudio Holanda (@kazzkiq)
Top Related Projects
A CSS only tooltip library for your lovely websites.
Tooltip, popover, dropdown, and menu library
A JavaScript library to position floating elements and create interactions for them.
💬 Minimal, accessible, ultra lightweight css tooltip library. Just 1kb.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot