Display sidebar only if it has content

You can use is_active_sidebar to check if sidebar has any widgets or not. Display sidebar only if is_active_sidebar returns true.

<?php if ( is_active_sidebar( 'sidebar-name' ) ) : ?>
    <?php dynamic_sidebar( 'sidebar-name' ); ?>
<?php endif; ?>