HTML onoffline Event Attribute


The onoffline HTML event attribute triggers when the browser starts to work offline. This can happen for a variety of reasons, such as the user disconnecting from the internet or the network being unavailable.

The onoffline event attribute can be used to notify the user that the browser is offline and to take appropriate action. For example, a website could use the onoffline event attribute to display a message to the user informing them that they are offline and that certain features may not be available. The website could also use the onoffline event attribute to disable certain features, such as online forms or video streaming.

The onoffline event attribute is only supported by the <body> tag.

Here is an example of how to use the onoffline event attribute:

<body onoffline="alert('You are now offline.')">

When the browser goes offline, an alert message will be displayed to the user.

It is important to note that the onoffline event attribute does not guarantee that the browser will be completely offline. It is possible that the browser may still be able to access certain resources, such as cached files or local storage. However, the onoffline event attribute can be used to take precautionary measures to ensure that the user has a good experience even when the browser is offline.


<element onoffline="script">


  • scriptThe name of the script to use when the event has been triggered.


<body ononline="onFunction()" onoffline="offFunction()">

<p>Open the File menu and click on the “Work offline” button to switch between working on onlie and offline.</p>

<p><strong>Note:</strong>Ononline and onoffline events are supported only in Firefox and Internet Explorer from versions 8 to 10.</p>

function onFunction() {
alert ("EXAMPLE: Your browser is online.");

function offFunction() {
alert ("EXAMPLE: Your browser is offline.");


Browser Support

The following table will show you the current browser support for the HTML onoffline Event Attribute.

Edge Chrome Firefox Opera Safari
Tablets / Mobile
Chrome Firefox Opera Safari Samsung Webview

Last updated by CSSPortal on: 14th October 2023