Skip to main content

Overview

The Notice class displays temporary notifications at the top of the Obsidian window. Use notices to provide feedback about actions, display errors, or communicate important information to users. Since: 0.9.7

Constructor

message
string | DocumentFragment
required
The message to display. Can be a simple string or a DocumentFragment for rich content.
duration
number
Time in milliseconds to show the notice. If set to 0, the notice will stay visible until the user manually dismisses it. Default duration is typically a few seconds.
// Simple notice
new Notice('File saved successfully!');

// Notice with custom duration (5 seconds)
new Notice('This message will disappear in 5 seconds', 5000);

// Persistent notice (must be manually dismissed)
new Notice('This notice stays until dismissed', 0);

Properties

noticeEl
HTMLElement
deprecated
The notice element. Deprecated: Use messageEl instead.Since: 0.9.7
containerEl
HTMLElement
The outer container element of the notice.Since: 1.8.7
messageEl
HTMLElement
The element containing the notice message. You can modify this element to add custom content.Since: 1.8.7

Methods

setMessage()

Changes the message displayed in the notice.
message
string | DocumentFragment
required
The new message to display
const notice = new Notice('Loading...');
// Later, update the message
notice.setMessage('Done!');
Returns: this (for chaining) Since: 0.9.7

hide()

Manually dismisses and hides the notice.
const notice = new Notice('This will be hidden immediately', 0);
notice.hide();
Since: 0.9.7

Examples

Basic Success Notice

import { Notice } from 'obsidian';

new Notice('✅ File saved successfully!');

Error Notice

import { Notice } from 'obsidian';

new Notice('❌ Failed to save file. Please try again.', 5000);

Loading Notice with Update

import { Notice } from 'obsidian';

const notice = new Notice('Loading data...', 0);

try {
  await loadData();
  notice.setMessage('✅ Data loaded successfully!');
  setTimeout(() => notice.hide(), 2000);
} catch (error) {
  notice.setMessage('❌ Failed to load data');
  setTimeout(() => notice.hide(), 3000);
}

Rich Content Notice

import { Notice } from 'obsidian';

const fragment = document.createDocumentFragment();
const container = fragment.createDiv();
container.createEl('strong', { text: 'Important: ' });
container.createSpan({ text: 'Your changes have been saved.' });

const notice = new Notice(fragment, 4000);

Persistent Notice with Manual Control

import { Notice } from 'obsidian';

// Create a notice that doesn't auto-dismiss
const notice = new Notice('Click to dismiss', 0);

// Add a click handler to the notice element
notice.messageEl.addEventListener('click', () => {
  notice.hide();
});

Best Practices

  • Use notices sparingly to avoid overwhelming users
  • Keep messages concise and actionable
  • Use appropriate durations (2-5 seconds for most notices)
  • Reserve persistent notices (duration = 0) for critical information that requires acknowledgment
  • Include emoji or icons to quickly convey message type (✅ success, ❌ error, ℹ️ info)

See Also

  • Modal - For more complex user interactions requiring a full modal dialog

Build docs developers (and LLMs) love